Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, July 10, 2018 11:21 PM
I will try to make this short as possible. I already have code set to make an http request. it works and the request is made and I don't receive errors. I do however get errors attempting to parse the response. Instead of posting what I have I will just ask this. Based on the below response how would you parse it? It appears to be JSON I think. I get null back in my request so it fails. I am not sure how to best ask this question now that I am typing it. I will start with posting the http response I guess. I am not opposed to ditching all the code I have that doesnt work and starting from scratch...
So if you were doing this how would you do it?
When I run it through my app I get nothing. I tried to parse it as JSON and I get this error
Invalid JSON primitive: System.Net.HttpWebResponse.'
This is the response as intercepted by Burp Suite
HTTP/1.1 200 OK
Date: Tue, 10 Jul 2018 23:15:10 GMT
strict-transport-security: max-age=31536000; includeSubDomains
X-Powered-By: Servlet/3.0
Cache-Control: must-revalidate, max-age=0
Expires: Tue, 10 Jul 2018 23:25:10 GMT
Connection: close
Content-Type: application/json
Content-Language: en-US
X-Iinfo: 5-126711005-126711029 NNNN CT(76 79 0) RT(1531264508915 133) q(0 0 2 -1) r(3 3) U2
X-CDN: Incapsula
Content-Length: 361
{"success":true,"data":{"parts":[["102116330200","PIN,PISTON","13.49","6.70","","In Stock",["1","4","0"],"","","07-10-2018"],["102116330200","PIN,PISTON","13.49","6.70","","In Stock",["1","4","0"],"","","07-10-2018"],["102116330200","PIN,PISTON","13.49","6.70","","In Stock",["1","4","0"],"","","07-10-2018"]],"warehouses":["Wisconsin","Georgia","California"]}}
All replies (3)
Wednesday, July 11, 2018 5:22 AM
Show your code that parses the result. You probably should extract the JSON string from HttpWebResponse.GetResponseStream using StreamReader.ReadToEnd, then parse it.
Wednesday, July 11, 2018 6:01 AM
Hi,
I'm afraid you need to provide your code here, I'm not sure how did you use the web request and response in your code, the following documents may help you:
How to: Request Data Using the WebRequest Class
How to: Send Data Using the WebRequest Class
How to use HttpWebRequest and HttpWebResponse in .NET
Regards,
Stanly
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].
Wednesday, July 11, 2018 7:00 AM
If you had searched for the error, you would have found your exact problem. You are doing something like this
strResponse = Request.GetResponse().ToString();
but that's wrong. GetResponse() returns an object of type System.Net.HttpWebResponse, and the ToString() method just returns the type name.
Instead you need to fetch the response stream, which you can get from:
respStream = Request.GetReponse().GetResponseStream();
Then you can read the response text from that stream.
Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.