RT接口协议:
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "/FeedBack/Submit", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
ErrorCode SubClientFeedback(FeedBack userFeedBack);Client:
string strText;
Uri address = new Uri("http://mobi4biz.net" + "/mobi4bizservice.svc/FeedBack/Submit");
// Create the web request
HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
// Set type to POST
request.Method = "POST";
request.ContentType = "application/json; charset=utf-8";
//request.ContentType = "text/x-json";
// Create the data we want to send
string data = "{ \"usrID\": 1, \"FeedBackType\": 1, \"ContactName\": \"afd dfad \", \"ContactPhone\": \"123534234\", \"ContactEmail\": \"[email protected]\"}";
// Create a byte array of the data we want to send
byte[] byteData = UTF8Encoding.UTF8.GetBytes(data);
// Set the content length in the request headers
request.ContentLength = byteData.Length;
// Write data
using (Stream postStream = request.GetRequestStream())
{
postStream.Write(byteData, 0, byteData.Length);
}
// Get response
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
StreamReader reader = new StreamReader(response.GetResponseStream());
// Console application output
strText = strText + reader.ReadToEnd();
}
strText = strText + "\n";
lblStatus.Text = strText;我用AJAX调用也是同样的问题。
function HttpPost() {
var str = "{ \"usrID\": 1, \"FeedBackType\": 1, \"ContactName\": \"afd dfad \", \"ContactPhone\": \"123534234\", \"ContactEmail\": \"[email protected]\"}";
$.ajax({
type: "POST",
contentType: "application/json",
url: "http://localhost:6023/Testservice.svc/FeedBack/Submit",
data: str,
success: function(data) {
$("#TextPost").val(data);
}
});
}不知道是什么问题?会不会是namespace的问题?请高手指点一下!谢谢!!!!
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "/FeedBack/Submit", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
ErrorCode SubClientFeedback(FeedBack userFeedBack);Client:
string strText;
Uri address = new Uri("http://mobi4biz.net" + "/mobi4bizservice.svc/FeedBack/Submit");
// Create the web request
HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
// Set type to POST
request.Method = "POST";
request.ContentType = "application/json; charset=utf-8";
//request.ContentType = "text/x-json";
// Create the data we want to send
string data = "{ \"usrID\": 1, \"FeedBackType\": 1, \"ContactName\": \"afd dfad \", \"ContactPhone\": \"123534234\", \"ContactEmail\": \"[email protected]\"}";
// Create a byte array of the data we want to send
byte[] byteData = UTF8Encoding.UTF8.GetBytes(data);
// Set the content length in the request headers
request.ContentLength = byteData.Length;
// Write data
using (Stream postStream = request.GetRequestStream())
{
postStream.Write(byteData, 0, byteData.Length);
}
// Get response
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
StreamReader reader = new StreamReader(response.GetResponseStream());
// Console application output
strText = strText + reader.ReadToEnd();
}
strText = strText + "\n";
lblStatus.Text = strText;我用AJAX调用也是同样的问题。
function HttpPost() {
var str = "{ \"usrID\": 1, \"FeedBackType\": 1, \"ContactName\": \"afd dfad \", \"ContactPhone\": \"123534234\", \"ContactEmail\": \"[email protected]\"}";
$.ajax({
type: "POST",
contentType: "application/json",
url: "http://localhost:6023/Testservice.svc/FeedBack/Submit",
data: str,
success: function(data) {
$("#TextPost").val(data);
}
});
}不知道是什么问题?会不会是namespace的问题?请高手指点一下!谢谢!!!!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货