Guest User

Untitled

a guest
Nov 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. var values = new NameValueCollection();
  2. values["clientId"] = clientId;
  3. values["clientIP"] = currentIP;
  4.  
  5. byte[] response;
  6. var resultResponse = string.Empty;
  7.  
  8. using (var client = new WebClient())
  9. {
  10. try {
  11. response = client.UploadValues(url, values);
  12. resultResponse = Encoding.Default.GetString(response);
  13. }
  14. catch (WebException e)
  15. {
  16. string exception = string.Empty;
  17. if (e.Status == WebExceptionStatus.ProtocolError)
  18. {
  19. exception += ((HttpWebResponse)e.Response).StatusCode;
  20. exception += ((HttpWebResponse)e.Response).StatusDescription;
  21. }
  22. }
  23. }
  24.  
  25. string method = "post";
  26. WebRequest req = WebRequest.Create(uri);
  27. req.ContentType = contentType;
  28. req.Method = method;
  29. req.Headers.Add("myhead", value);
  30.  
  31. req.ContentLength = jsonDataBytes.Length;
  32. var stream = req.GetRequestStream();
  33. stream.Write(jsonDataBytes, 0, jsonDataBytes.Length);
  34. stream.Close();
  35. var response = req.GetResponse().GetResponseStream();
  36. StreamReader reader = new StreamReader(response);
  37. var res = reader.ReadToEnd();
  38. reader.Close();
  39. response.Close();
  40. return res;
Add Comment
Please, Sign In to add comment