I am using below IronPython code for request web method with GET. It's worked with POST method. Then I change the post method into GET request.Method = "GET"
and there after this example not work for GET method.
from System.Net import WebRequest
from System.IO import StreamReader
from System.Text import Encoding
def UrlOpen(uri, parameters=None):
request = WebRequest.Create(uri)
if parameters is not None:
request.ContentType = "application/x-www-form-urlencoded"
#request.Method = "POST" #work for post
request.Method = "GET" #not work for get method
bytes = Encoding.ASCII.GetBytes(parameters)
request.ContentLength = bytes.Length
reqStream = request.GetRequestStream()
reqStream.Write(bytes, 0, bytes.Length)
reqStream.Close()
response = request.GetResponse()
result = StreamReader(response.GetResponseStream()).ReadToEnd()
return result
print(UrlOpen("http://localhost:89/api/","data=1"))
PHP Code for web service just:
<?php
echo $_POST["data"];
?>
It's displayed below error on Python console after changing request.Method = "GET"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "<string>", line 9, in UrlOpen
SystemError: Cannot send a content-body with this verb-type.