TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Arvind Chourasiya
NA
933
134.9k
How to covert HttpWebRequest implementation to HttpClient
Nov 6 2018 2:17 AM
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;
}
Now the same thing I need to do in
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.
Reply
Answers (
1
)
How Av software works?
can i do a overload for this ">>=" operator ?