Question Python httpServ.request in C# - HttpWebRequest ?

yshimoni

New member
Joined
Oct 3, 2018
Messages
2
Programming Experience
Beginner
Hi,
New to this and need some help...
I’m struggling with converting Python code to C#, I have this line in the Python code and I’m not sure how to implement it in C#:


self.httpServ.request('GET', '/loadinst.cgi'%cmd_type, "<EEX Ver='1.0'><CMD type=%s /></EEX>" % cmd)

Wireshark looks like this:


Hypertext Transfer Protocol
GET /loadinst.cgi HTTP/1.1\r\n
Host: xxx.xxx.xxx.148\r\n
Accept-Encoding: identity\r\n
Content-Length: 119\r\n
\r\n
[Full request URI: http://xxx.xxx.xxx.148/loadinst.cgi]
[HTTP request 1/1]
[Response in frame: 30]
File Data: 119 bytes
Data
[Length: 119]
<EEX Ver='1.0'><CMD type='loadinst' DriverStatusCode='0' emAdapterType='EEXp' id='0' instrumentType='' ipSA='' /></EEX>



My C# implementation is:

var URL1 = (URL + cmd);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL1);
request.Method = "GET";
WebResponse response = request.GetResponse();


but Wireshark capture like:

GET /loadinst.cgi <EEX Ver='1.0'><CMD ....
Host: xxx.xxx.xxx.148
Accept-Encoding: identity

Data field is empty and the remote instrument drops the connection...
How the get the data correctly with GET method as its working with the Python?

Thanks,
 
string html = string.Empty;
string url = @"https://x.x.x.x/loadinst.cgi?paramx=x&paramy=y";

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request
.AutomaticDecompression = DecompressionMethods.GZip;

using
(HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using
(Stream stream = response.GetResponseStream())
using
(StreamReader reader = new StreamReader(stream))
{
html
= reader.ReadToEnd();
}

Console.WriteLine(html);
 
Thanks but its not working... same as my try, there is no `data` feild...

To be honest not sure if its possible with GET but this what i see with the Wireshark .... i need to get the same with the C# code.

Hypertext Transfer Protocol
GET /loadinst.cgi HTTP/1.1\r\n
Host: xxx.xxx.xxx.148\r\n
Accept-Encoding: identity\r\n
Content-Length: 119\r\n
\r\n
[Full request URI: http://xxx.xxx.xxx.148/loadinst.cgi]
[HTTP request 1/1]
[Response in frame: 30]
File Data: 119 bytes
Data
[Length: 119]
<EEX Ver='1.0'><CMD type='loadinst' DriverStatusCode='0' emAdapterType='EEXp' id='0' instrumentType='' ipSA='' /></EEX>
 
Right, without knowing the implementation of what you actually are calling (the loadinst thing) it might not be possible to use the GET, maybe try with POST, but hard to elaborate without knowing more about what is on the "other side"...
 

Latest posts

Back
Top Bottom