Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private Tuple<int, string> SendData2(string JsonData, string url, string username, string password)
- {
- UTF8Encoding encoding = new UTF8Encoding();
- //string url = "http://rtflistener-u001.elasticbeanstalk.com/Listener.ashx";
- //string username = "username";
- //string password = "password";
- HttpWebRequest httpWebReq = (HttpWebRequest)WebRequest.Create(url);
- string requestString = "username=" + username + "&password=" + password + "&data=" + JsonData;
- byte[] cData = encoding.GetBytes(requestString);
- httpWebReq.Method = "POST";
- httpWebReq.ContentType = "application/x-www-form-urlencoded";
- httpWebReq.ContentLength = cData.Length;
- httpWebReq.Timeout = 30000;
- string responseString = "";
- int statusCode = 0;
- try
- {
- using (Stream stream = httpWebReq.GetRequestStream())
- {
- stream.Write(cData, 0, cData.Length);
- }
- HttpWebResponse httpResponse = (HttpWebResponse)httpWebReq.GetResponse();
- responseString = new StreamReader(httpResponse.GetResponseStream()).ReadToEnd();
- statusCode= (int)httpResponse.StatusCode;
- //200
- }
- catch (WebException ex)
- {
- statusCode = (int)ex.Status;
- HttpWebResponse httpResponse = (HttpWebResponse)ex.Response;
- responseString = new StreamReader(httpResponse.GetResponseStream()).ReadToEnd();
- //400, 500
- }
- catch (Exception ex)
- {
- }
- return new Tuple<int, string>(statusCode, responseString);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement