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
Praveen Kumar
281
6.6k
2.3m
Error while consuming API into .NET 3.5 with VS2008 into Console App
Dec 9 2020 11:34 PM
Note:
The same code when I am execution on dotnetfiddle.net where framework version is v4.7. It is working perfectly. While the code I have written is compatible with v3.5
I am consuming an API into .NET 3.5 using Visual Studio 2008 using WebRequest. Following are the details of API:
Method:
POST
ConetntType:
application/x-www-form-urlencoded
With Three Parameters.
Key
Value
ApiKey string
ApiOwner string
RequestBody json string
I am using the following code pattern.
WebRequest request = WebRequest.Create(
"https://hostname/RestWS/api/v1/order/orderPull"
);
request.Method =
"POST"
;
string
postData =
"ApiOwner=sa&ApiKey=d564078......9530dec&RequestBody="
;
postData = postData +
"{ \"orderNo\":\"o81075084\",\n \"statuses\":[],\n \"fromDate\":\"\",\n \"toDate\":\"\",\n \"pageNumber\":\"\",\n \"order_Location\":\"\",\n \"IsReplacementOrder\":\"\",\n \"orderSource\":\"\",\n \"paymentType\":[\"Prepaid\",\"COD\"]\n }"
;
byte
[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType =
"application/x-www-form-urlencoded"
;
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream(); //Error at this line
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
dataStream = response.GetResponseStream();
StreamReader reader =
new
StreamReader(dataStream);
string
responseFromServer = reader.ReadToEnd();
Console.WriteLine(responseFromServer);
reader.Close();
dataStream.Close();
response.Close();
Exception
Inner Exception:
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
Reply
Answers (
5
)
tel me how to remove data from list using LINQ
need explanation C# below code