EXAMPLE_1
PARAMETER
wsUrlPath = http://localhost/WaWebService/Json/Login
FUNCTION
protected string getResponseStringByUrl(string wsUrlPath, string userName, string password)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(wsUrlPath);
//request.Credentials = new NetworkCredential("admin", "");
byte[] authBytes = Encoding.UTF8.GetBytes((userName + ":" + password).ToCharArray());
request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(authBytes);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string res = this.getStringFromResponse(response);
return res;
}
EXAMPLE_2
PARAMETER
wsUrlPath = http://localhost/WaWebService/Json/GetTagValueText/{PROJECT_NAME}
contentType = "application/json"
method = System.Net.WebRequestMethods.Http.Post
paramStr = JSONHelper.serialise(tagValueParamObj)
FUNCTION
protected string getResponseInString(string wsUrlPath, string contentType, string method, string paramStr, string userName, string password)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(wsUrlPath);
request.ContentType = contentType;
request.Method = method;
byte[] authBytes = Encoding.UTF8.GetBytes((userName + ":" + password).ToCharArray());
request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(authBytes);
byte[] reqBodyBytes = Encoding.UTF8.GetBytes(paramStr);
Stream reqStream = request.GetRequestStream();
reqStream.Write(reqBodyBytes, 0, reqBodyBytes.Length);
reqStream.Close();
// execute the request
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string res= this.getStringFromResponse(response);
return res;
}