{"id":1500,"date":"2017-01-11T20:20:28","date_gmt":"2017-01-11T20:20:28","guid":{"rendered":"http:\/\/62.131.51.129\/?p=1500"},"modified":"2017-01-11T20:20:28","modified_gmt":"2017-01-11T20:20:28","slug":"network-reaction-from-python","status":"publish","type":"post","link":"http:\/\/archief.van-maanen.com\/?p=1500","title":{"rendered":"Network reaction from Python"},"content":{"rendered":"<p>I have a php script that runs as cgi on a webserver. The programme is quite simple. First is asks for a userid and password. The userid and password are sent as a parameter. If these value coincide with expected value, the system returns a page where the user may click on a hyperlink to continue his journey.<br \/>\nWe thus have a stream with two parameters that is sent from the user browser to the webserver, upon which the system may react.<\/p>\n<p>It is possible to mimick this with a python programme that sends the same stream to the webserver. This programme looks like:<\/p>\n<pre>\nfrom urllib import request, parse\nurl='http:\/\/62.131.51.129\/load_pr\/password.php'\nparms = {\n    'txtUsername' : 'tom',\n    'txtPassword' : 'binvegni'\n        }\nquerystring = parse.urlencode(parms)\nu = request.urlopen(url, querystring.encode('ascii'))\nresp = u.read()\nprint (resp)\n<\/pre>\n<p>This stream is sent to the webserver that runs on http:\/\/62.131.51.129. It sends the same stream of bytes as requested from script http:\/\/62.131.51.129\/load_pr\/password.php as it contains two parameter values (&#8216;txtUsername&#8217;, &#8216;txtPassword&#8217;).<br \/>\nWe call this Python programme with &#8220;D:\\Users\\tmaanen\\Documents>python sendPost.py&#8221;. The answer received is:<\/p>\n<p><a href=\"http:\/\/62.131.51.129\/wp-content\/uploads\/2017\/01\/Untitled.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/62.131.51.129\/wp-content\/uploads\/2017\/01\/Untitled.png\" alt=\"\" width=\"798\" height=\"106\" class=\"alignnone size-full wp-image-1505\" \/><\/a><br \/>\nThis matches the stream as sent by the webserver as from the php script.<\/p>\n<p>Finally, in case of get instead of post, the programme is slightly different:<\/p>\n<pre>\nfrom urllib import request, parse\nurl='http:\/\/62.131.51.129\/load_pr\/password.php'\nparms = {\n    'txtUsername' : 'tom',\n    'txtPassword' : 'bunvegni'\n        }\nquerystring = parse.urlencode(parms)\nu = request.urlopen(url+'?'+querystring)\nresp = u.read()\nprint (resp)\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I have a php script that runs as cgi on a webserver. The programme is quite simple. First is asks for a userid and password. The userid and password are sent as a parameter. If these value coincide with expected value, the system returns a page where the user may click on a hyperlink to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1501,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1500","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-nice-to-know"],"_links":{"self":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/1500","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1500"}],"version-history":[{"count":0,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/1500\/revisions"}],"wp:attachment":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1500"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1500"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1500"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}