C#服务的 iOS客户端

BlueFogs 2016-09-24 11:54:23
C#写的WCF,iOS做客户端,GET请求完全没问题,但是post接口调用报错400


[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "InsertAOrder")]
Dictionary<string, string> InsertAOrder(Stream stream);

public Dictionary<string, string> InsertAOrder(Stream stream)
{
StreamReader reader = new StreamReader(stream);
string str = reader.ReadToEnd();
reader.Dispose();
JavaScriptSerializer serializer = new JavaScriptSerializer();
Dictionary<string, object> paramDic = serializer.Deserialize<Dictionary<string, object>>(str);

Dictionary<string, string> dic = new Dictionary<string, string>();

string sqlString = " insert into [C1NWind].[dbo].[Order] (ID,CustomerID,ProductID,PurchaseDate,Time,PaymentType,PaymentAmount,Quantity) values(2001,200,200,GETDATE(),GETDATE(),'Candy',100,9)";
SqlCommand com = new SqlCommand(sqlString,FJCon);

FJCon.Open();
try{
int rcount = com.ExecuteNonQuery();
if(rcount > 0){
dic.Add("result","1");
dic.Add("Pinsert", "AOrder");
} else{
dic.Add("result","0");
}
}
catch (Exception ex)
{
dic.Add("result","0");
dic.Add("exception", ex.Message.ToString());
}
FJCon.Close();

return dic;
}




[RequestManager POST:@"InsertAOrder" params:dictionary success:^(id response) {
NSLog(@"%@",response);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"%@",error);
}];


AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/json",@"text/html",@"text/plain", nil];

// 请求超时时间
manager.requestSerializer.timeoutInterval = 30;
NSString *postStr = URL;
if (![URL hasPrefix:@"http"]) {

postStr = [NSString stringWithFormat:@"%@%@", ServerUrl,URL] ;
}
NSMutableDictionary *dict = [params mutableCopy];

// 发送post请求
[manager POST:postStr parameters:dict success:^(AFHTTPRequestOperation *operation, id responseObject) {

// 请求成功
NSDictionary *responseDict = (NSDictionary *)responseObject;
success(responseDict);

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {// 请求失败
Error( operation,error);

}];





失败

Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: bad request (400)"

status code: 400, headers {
"Cache-Control" = private;
"Content-Length" = 1643;
"Content-Type" = "text/html";
Date = "Sat, 24 Sep 2016 03:51:50 GMT";
Server = "Microsoft-IIS/7.5";
"X-AspNet-Version" = "4.0.30319";
"X-Powered-By" = "ASP.NET";

...全文
251 4 打赏 收藏 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Justin-Liu 2016-09-26
  • 打赏
  • 举报
回复
debug一下wcf
BlueFogs 2016-09-26
  • 打赏
  • 举报
回复
这个是iOS 调用接口的报错信息啊
BlueFogs 2016-09-26
  • 打赏
  • 举报
回复
引用 3 楼 FoxDave 的回复:
debug一下wcf
在C#客户端调用这个post接口是没问题的,那wcf应该也没问题,但iOS端调用就不行
Poopaye 2016-09-24
  • 打赏
  • 举报
回复
引用
com.alamofire.error.serialization.response Code=-1011
这个是什么意思?

111,128

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧