-
Dec 24th, 2013, 12:26 PM
#1
[RESOLVED] Web Request Request Response
Yeah, the subject line is goofy, but that's how I am.
I have a WebRequest that I am using like this:
Code:
Try
Dim httpResponse = upRequest.GetResponse
sReader = New StreamReader(httpResponse.GetResponseStream)
Dim result = sReader.ReadToEnd
Catch ex As System.Net.WebException
sReader = New StreamReader(ex.Response.GetResponseStream)
Dim result = sReader.ReadToEnd
result = result
End Try
This seems like a remarkably poor way to do things, which is what I'm asking about. The upRequest object is an HttpWebRequest which is set up so that it is almost right. Some of the data I am passing to it is not quite right (it's a JSON string with some typos in some fields) because I want to get errors back from this service (we're still thrashing out what validation will be done on the data being sent to them). Because of the errors in the JSON string, I get back an error 422 from the service, which is correct. I think the typical 422 has been hijacked, in this case, to indicate that there were validation errors in the data submitted.
It seems unreasonable that I should need to use exception handling when I am getting back a perfectly good scolding from the webservice. It was just a bad code, not all that exceptional at all. Do I really need to handle it via exception handling?
However, the exception handling works. The result = result line is just there because I wanted a place to put a breakpoint. After all, I've yet to decide what to do with that result. The error response should be a JSON string showing me the validation errors on the record I submitted. That JSON string is there, but the string 'result' has a preamble before the JSON string. The preamble is, "The custom error module does not recognize this error." I could simply strip that preamble off the response and parse the rest back from the JSON that it is, but this all seems terribly clunky to me. I'm looking for a better way. Any suggestions?
My usual boring signature: Nothing
-
Jan 7th, 2014, 04:03 PM
#2
Re: [RESOLVED] Web Request Request Response
With no responses, as goofy a solution as this seems to be, it looks like it is still the way to go.
My usual boring signature: Nothing
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|