I have one service method which is using
HttpWebRequest for below stuff- while (ub < sentCount)
- {
- ub = step * (1 + (i++));
- var k = (ub > sentCount) ? (sentCount) : ub; //to avoid array out of range exception(assign unitll array length if calc exceeds)
- for (int j = lb; j < k; j++)
- {
- pnos = pnos + "," + pnosList[j].Phone;
- }
- pnos = pnos.Substring(1);
- var sbPostData = new StringBuilder();
- sbPostData.AppendFormat("authkey={0}", api.AuthenticationKey);
- sbPostData.AppendFormat("&mobiles={0}", pnos);
- sbPostData.AppendFormat("&message={0}", message);
- sbPostData.AppendFormat("&sender={0}", api.SenderId);
- sbPostData.AppendFormat("&route={0}", "default");
- string sendSMSUri = api.EndPoint;
- // Create HTTPWebrequest
- var httpWReq = (HttpWebRequest)WebRequest.Create(sendSMSUri);
- //Prepare and Add URL Encoded data
- var encoding = new UTF8Encoding();
- byte[] data = encoding.GetBytes(sbPostData.ToString());
- //Specify post method
- httpWReq.Method = "POST";
- httpWReq.ContentType = "application/x-www-form-urlencoded";
- //httpWReq.ContentLength = data.Length;
- using (Stream stream = httpWReq.GetRequestStream())
- {
- stream.Write(data, 0, data.Length);
- }
- //Get the response
- var response = (HttpWebResponse)httpWReq.GetResponse();
- var reader = new StreamReader(response.GetResponseStream());
- string responseString = reader.ReadToEnd();
- //Close the response
- reader.Close();
- response.Close();
- lb = ub;
- pnos = string.Empty;
- }
HttpClient is it possible to do that. Issue I am facing is HttpWebRequest is not supporting in PCL(C# class library) I want to move above logic to PCL.1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Madan ShekarPosted Nov 6, 2018, 3:06 AM
{
{"token", token},
{"forStorage", "true"},
{"MaxBatchSize", "1000"},
{"outFields", "*"},
{"f", "json"},
{"addresses", inputJson} //inputJson is an array of a complex type
};
using (var client = new HttpClient())
{
try
{
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync(url, content);
Task
string outputJson = await responseString;
res = JsonConvert.DeserializeObject
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString()); //"Invalid URI: The Uri string is too long."
}
}
using (var client = new HttpClient())
{
try
{
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync(url, content);
Task
string outputJson = await responseString;
res = JsonConvert.DeserializeObject
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString()); //"Invalid URI: The Uri string is too long."
}
}