Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Unexpected character encountered while parsing value: H. Path '', line 0, position 0 Newtonsoft.Json.JsonReaderException

What I have tried:

string title = TextBox1.Text;
string description = TextBox2.Text;
string unitType = ddlUnitType.SelectedValue;
string RequestType = ddlRequestType.SelectedValue;
string pricefrom = txtpricefrom.Text;
string priceto = txtpriceto.Text;
string areafrom = txtAreafrom.Text;
string areato = txtAreato.Text;
string Send_Data = String.Format("request[title]={0}&request[description]={1}&request[type]={2}&request[request_type]={3}&request[price_from]={4}&request[price_to]={5}&request[area_from]={6}&request[area_to]={7}", title, description,unitType,RequestType,pricefrom,priceto,areafrom,areato);

string url = "https://test.com/api/saveRequest?" + Send_Data;
string Requestbody = "";

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";

request.Headers.Add("token", "222222");


System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
Byte[] byteArray = encoding.GetBytes(Requestbody);
request.ContentLength = byteArray.Length;
// request.ContentType = @"application/form-data";
request.ContentType = @"application/json";
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;



using (Stream data = request.GetRequestStream())
{
data.Write(byteArray, 0, byteArray.Length);
}

IAsyncResult asyncResult = request.BeginGetResponse(null, null);
asyncResult.AsyncWaitHandle.WaitOne();

using (WebResponse webResponse = request.EndGetResponse(asyncResult))
{
using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
{
var result = rd.ReadToEnd();


dynamic _json = JsonConvert.DeserializeObject(result);
dynamic _result = new ExpandoObject();
var all_data = _json["status"];

if (all_data == "true")
{
lblmessege.Text = "Saved";

}

else
{
lblmessege.Text = "Not Saved";
}
Posted
Updated 18-Apr-20 0:45am
v2
Comments
MadMyche 13-Apr-20 19:57pm    
Inquiring minds want to know: What is actually being returned in that WebResponse?

1 solution

This is not a question, but...

To find your issue, put a breakpoint at this line:

C#
dynamic _json = JsonConvert.DeserializeObject(result);

And inspect the variable result. Step through the code, and inspect all associated objects. I *guarantee* you'll find out what's wrong with your code.

Learning how to use the tools at your disposal will assist you in learning how to be a programmer.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900