gpt4 book ai didi

.net - 如何从提供 json 输出的 dot net webservices 检索值?

转载 作者:行者123 更新时间:2023-11-29 04:09:23 26 4
gpt4 key购买 nike

在我的应用程序中,我使用 SBJson 来解析值。 Web 服务是在 dot net 中开发的。对于 php Web 服务,代码工作得很好,但是对于 .net Web 服务,代码没有显示响应值。代码中没有错误、异常或警告。

这是 Web 服务的 JSON 输出:

{ "Head":[ { "id":"0","msg":"Username or Password Not Match"} ]}

这里的用户名密码是错误的,但我的代码甚至没有返回任何错误的值。

这是我的代码:

NSString *post = [NSString stringWithFormat:@"key=%@&username=%@&password=%@",key.text,[txtUsername text],[txtPassword text]];
NSLog(@"PostData: %@",post);

NSURL *url = [NSURL URLWithString:@"http://jabdcdfddfsd.aspx"];

NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSLog(@"%@", postData);

NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSLog(@"%@",postLength);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];

NSLog(@"%@",request);
NSError *error = [[NSError alloc] init];
NSHTTPURLResponse *response = nil;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSLog(@"%@",response);

NSLog(@"Response code: %d", [response statusCode]);
if ([response statusCode] >=200 && [response statusCode] <300)
{
NSString *responseData = [[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(@"Response ==> %@", responseData)

帮帮我。 responseData 没有打印任何内容。我的代码中有任何问题,或者问题出在另一端,我的意思是在 dotnet Web 服务中。

最佳答案

我认为如果代码在旧的 php Web 服务上运行良好,您应该仔细检查您的 .Net Web 服务。很可能在某些方面有所不同。尝试使用类似 Chrome Advanced REST client 的内容查看每个网络服务如何响应。

关于.net - 如何从提供 json 输出的 dot net webservices 检索值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14661793/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com