gpt4 book ai didi

ios - 在 afnetworking 3.0 中发布请求?

转载 作者:行者123 更新时间:2023-11-29 00:54:52 26 4
gpt4 key购买 nike

我有一个应用程序,我在其中使用 Afnetnetworking3.0 进行这样的 Web 服务调用。

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager setRequestSerializer:[AFJSONRequestSerializer serializer]];
[manager setResponseSerializer:[AFJSONResponseSerializer serializer]];

NSURL * urlStr = [NSURL URLWithString:path];

NSDictionary *parameters = @{@"ID":@"fdfdfd",@"No":@"1414"};
NSLog(@"%@",parameters);

[manager POST:urlStr.absoluteString
parameters:parameters
progress:nil
success:^(NSURLSessionDataTask *task, id responseObject) {

NSLog(@"JSON: %@", responseObject);

} failure:^(NSURLSessionDataTask *task, NSError *error) {

NSLog(@"Error: %@", error);
}];

但它在参数字典中添加了一些空格并导致找不到 URL。谁能告诉我哪里出错了?

最佳答案

像这样尝试:

   NSString *Loginurl = [NSString stringWithFormat:@"http://Enter your url here"];


NSDictionary *params = @{
@"ID":@"fdfdfd",
@"No":@"1414"
};

NSLog(@"Sent parameter to server 1 : %@",params);
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];

manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];

manager.responseSerializer = [AFHTTPResponseSerializer serializer];

AFSecurityPolicy* policy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];

[policy setValidatesDomainName:NO];

[policy setAllowInvalidCertificates:YES];

manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];

manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/html",nil];

manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/plain",nil];



[manager POST:Loginurl parameters:params progress:nil success:^(NSURLSessionTask *task, id responseObject) {


NSLog(@"Response from server 1 : %@", [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]);

[self getdata:responseObject];


}
failure:^(NSURLSessionTask *operation, NSError *error)

{

NSLog(@"Error: %@", error);

}];
}


-(void)getdata:(NSDictionary*)RegisterData
{


}

检查日志已向服务器1发送参数...并检查您的url是否正确?

关于ios - 在 afnetworking 3.0 中发布请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37703420/

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