c# - How to get server response in JSON? -
i uploading .json file local drive:
using (webclient client = new webclient()) { client.headers.add("content-type", "application/json"); byte[] resp = client.uploadfile("http://mycoolwebsite.com", "post", "path file"); string textresponse = system.text.encoding.ascii.getstring(resp) }
the response client.uploadfile
of type byte[]
when want json can more parse through it. how can ask server give me json?
the method defined returning byte[]
reason. allows method used web service , return raw response server. defining server-side response responsibility of server (obviously). best bet take raw response, encode text (as you're doing), , check see if response contains well-formed json, allowing re-encode json , parse @ time.
the response whatever server returns; it's handle it.
Comments
Post a Comment