How do i pass parameters and header to an url using system.net.httpPost() function.
If you’re on a recent 8.0 version, you can use system.net.httpClient():
system.net.httpClient().post(url=url, params=parameters, headers=header).json
That said, using system.net.httpPost
should still work, but you’ll have to encode your URL parameters manually; the postData
parameter the function accepts indicates data to send in the request body, not as URL parameters, which it looks like you’re trying to do. You’ll need to manually append the parameters to the API URL you’re retrieving; something like:
import urllib
url = "http://192.168.1.598/api"
url += "?"
postParams = # some dictionary
header = #some dictionary
for k, v in postParams.items():
url += urllib.quote(k) + "=" + urllib.quote(v)
system.net.httpPost(url, headerValues=header)
2 Likes
Yes i actually did not define the parameters for system.net.httpPost() as defined.
Now its working fine.
I ll also try system.net.httpClient().
Thanks for the help
1 Like