質問するログイン新規登録

質問編集履歴

4

サーバのログ、POSTプログラムの更新

2017/07/02 14:26

投稿

kon_ta
kon_ta

スコア81

title CHANGED
File without changes
body CHANGED
@@ -81,9 +81,9 @@
81
81
 
82
82
  ```
83
83
  ```
84
- <プロキシサーバ上のログ>
84
+ <プロキシサーバ上のログ(POST)>
85
85
 
86
- 2017/07/01 17:36:52 [001] INFO: GOT request /index.php 172.20.69.88 POST http://172.20.69.88/index.php
86
+ 2017/07/02 23:18:03 [002] INFO: Got request /post/ httpbin.org POST http://httpbin.org/post/
87
- 2017/07/01 17:36:52 [001] INFO: Sending request POST https://172.20.69.88/index.php
87
+ 2017/07/02 23:18:03 [002] INFO: Sending request POST https://httpbin.org/post/
88
- 2017/07/01 17:36:52 [001] INFO: error read response 172.20.69.88 http: invalid Read on closed body
88
+ 2017/07/02 23:18:04 [002] INFO: error read response httpbin.org http: invalid Read on closed Body:
89
89
  ```

3

確認用POSTプログラムの追加

2017/07/02 14:26

投稿

kon_ta
kon_ta

スコア81

title CHANGED
File without changes
body CHANGED
@@ -62,6 +62,25 @@
62
62
  ValueError: No JSON object could be decoded
63
63
  ```
64
64
  ```
65
+ <POSTプログラム>
66
+ import pprint
67
+ import json
68
+ import requests
69
+
70
+ def main()
71
+ response = requests.post(
72
+ http://httpbin.org/post',
73
+ json,dumps({'foo':'bar'}),
74
+ headers={'Content-Type': 'application/json'})
75
+ pprint.pprint(response.json())
76
+
77
+
78
+ if __name__=='__main__':
79
+ main()
80
+
81
+
82
+ ```
83
+ ```
65
84
  <プロキシサーバ上のログ>
66
85
 
67
86
  2017/07/01 17:36:52 [001] INFO: GOT request /index.php 172.20.69.88 POST http://172.20.69.88/index.php

2

エラー情報の追加

2017/07/02 12:13

投稿

kon_ta
kon_ta

スコア81

title CHANGED
File without changes
body CHANGED
@@ -39,4 +39,32 @@
39
39
 
40
40
  if __name__ == '__main__':
41
41
  main()
42
+ ```
43
+ ```
44
+ <クライアントサイドのターミナルのエラー>
45
+ user@user-desktop:~$ python sample.py
46
+ {"press": 1020, "hum": 39.1, "temp": 21.8, "datetime": "2017/07/01 17:36:52"}
47
+ Traceback (most recent call last):
48
+ File "sample.py", line 28, in <module>
49
+ main()
50
+ File "sample.py", line 25, in main
51
+ uploadSensorValues(21.8, 39.1, 1020)
52
+ File "sample.py", line 20, in uploadSensorValues
53
+ print res.json()
54
+ File "/usr/lib/python2.7/dist-packages/requests/models.py", line 808, in json
55
+ return complexjson.loads(self.text, **kwargs)
56
+ File "/usr/lib/python2.7/json/__init__.py", line 339, in loads
57
+ return _default_decoder.decode(s)
58
+ File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
59
+ obj, end = self.raw_decode(s, idx=_w(s, 0).end())
60
+ File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
61
+ raise ValueError("No JSON object could be decoded")
62
+ ValueError: No JSON object could be decoded
63
+ ```
64
+ ```
65
+ <プロキシサーバ上のログ>
66
+
67
+ 2017/07/01 17:36:52 [001] INFO: GOT request /index.php 172.20.69.88 POST http://172.20.69.88/index.php
68
+ 2017/07/01 17:36:52 [001] INFO: Sending request POST https://172.20.69.88/index.php
69
+ 2017/07/01 17:36:52 [001] INFO: error read response 172.20.69.88 http: invalid Read on closed body
42
70
  ```

1

ソースコード追加

2017/07/01 08:44

投稿

kon_ta
kon_ta

スコア81

title CHANGED
File without changes
body CHANGED
@@ -6,4 +6,37 @@
6
6
  Pythonなどの言語で作成したプロキシサーバのような通信を中継する部分で、HTTP通信をHTTPS通信に
7
7
  変換して外部のサーバに送信するということは可能なのでしょうか?
8
8
 
9
- どなたか知識のある方、回答の方宜しくお願い致します。
9
+ どなたか知識のある方、回答の方宜しくお願い致します。
10
+
11
+
12
+ ###ソースコード(送信するjsonデータ)
13
+ ```ここに言語を入力
14
+ import requests
15
+ import json
16
+
17
+ from datetime import datetime
18
+
19
+ def uploadSensorValues(temp, hum, press):
20
+
21
+ url = 'http://172.20.69.88/index.php'
22
+
23
+ sensorsdata = {'datetime':datetime.now().strftime("%Y/%m/%d %H:%M:%S"),'temp':temp,'hum':hum,'press':press}
24
+
25
+ print json.dumps(sensorsdata)
26
+
27
+ headers = {'content-type': 'application/json'}
28
+ ps = {
29
+ "http": "http://172.20.69.177:8080",
30
+ }
31
+ res = requests.post(url, data=json.dumps(sensorsdata), headers=headers, verify=False,proxies = ps)
32
+
33
+ print res.json()
34
+ pass
35
+
36
+ def main():
37
+
38
+ uploadSensorValues(21.8, 39.1, 1020)
39
+
40
+ if __name__ == '__main__':
41
+ main()
42
+ ```