How to post JSON to the server cross domain?

NiceOne Team
NiceOne...
Admin
408 Points
69 Posts

Hi

I want to share:

How to post JSON to the server cross domain?

Views: 8126
Total Answered: 1
Total Marked As Answer: 0
Posted On: 27-Mar-2015 14:19

Share:   fb twitter linkedin
Answers
NiceOne Team
NiceOne...
Admin
408 Points
69 Posts
     

Hi,

The way I do it and is working is:

using System.IO;
using System.Net;

 

string url = "here the url";
var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.ContentType = "text/json";
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json = "{ \"text\" : \"value\"}";
 
streamWriter.Write(json);
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var responseText = streamReader.ReadToEnd();
//Now you have your response.
//or false depending on information in the response
return true;
}

 

 

Posted On: 27-Mar-2015 14:36
banner

Blog

Active User (0)

No Active User!
 Log In to Chat