0

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.
Simon Opelt
  • 6,136
  • 2
  • 35
  • 66
Elshan
  • 7,339
  • 4
  • 71
  • 106
  • 2
    What happens? "not working" is a bit broad ... what do you expect to happen when providing a message body in a GET? Have you seen http://stackoverflow.com/a/983458/468244 ? – Simon Opelt Feb 08 '17 at 11:35
  • we don't know your api on `http://localhost:89/api/` and, we don't know your error-message. please provide us some more info. – Matthias Burger Feb 08 '17 at 12:01
  • api is just print the parameter value. – Elshan Feb 08 '17 at 12:17
  • Not trying to be overly harsh @devopsEMK but how about googling "Cannot send a content-body with this verb-type." which yields http://stackoverflow.com/a/27421801/468244 or looking at [the documentation of the method you are calling](https://msdn.microsoft.com/en-us/library/d4cek6cc%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396)? – Simon Opelt Feb 08 '17 at 13:38

0 Answers0