ios - 发布到服务器,将 ASIFormDataRequest 替换为 AFnetworking

标签 ios http post afnetworking asiformdatarequest

我想在afnetworking中做一个post请求
这是我的 ASI 代码:

NSURL *mainurl = [NSURL URLWithString:@"xxxx/api/xxx/"];

    ASIFormDataRequest *requestt = [ASIFormDataRequest requestWithURL:mainurl];

    [requestt addPostValue:GETUnicidentifire forKey:@"UniqueId"];
    [requestt addPostValue:JsonOrderDetail   forKey:@"jsonProduct"];
    [requestt addPostValue:BranchId          forKey:@"BranchId"];
    [requestt addPostValue:OrderToTime       forKey:@"OrderToTime"];

    [requestt setCompletionBlock:^{
        // Process the response




    }];
    [requestt setFailedBlock:^{
        NSError *error = [requestt error];

如何在 AFnetworking 中做同样的丁字裤?

最佳答案

不是一个确切的答案,但这是来 self 的应用程序的一个非常相似的 POST 请求:

-(void)setGpsLocation:(CLLocation*)location success:(TPScopeInterfaceSuccess)success failure:(TPScopeInterfaceFailure)failure
{
    [_manager POST:@"gps/"
        parameters:@{
                     @"lat":@(location.coordinate.latitude),
                     @"lon":@(location.coordinate.longitude),
                     @"height":@(location.altitude),
                     }
     constructingBodyWithBlock:nil
           success:success
           failure:failure];
}

_manager 是 AFHTTPRequestOperationManager 的实例,初始化为:

_manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:@"http://192.168.1.1/"]];

关于ios - 发布到服务器,将 ASIFormDataRequest 替换为 AFnetworking,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22512517/

相关文章:

ios - 如何在导航 View Controller 中关闭整个 View Controller 堆栈?

ios - 图像不显示在 Firebase 的表格单元格中

ios - 关于如何在 iOS 中创建编码用户界面的提示

http - nginx 根据协议(protocol)提供页面

jquery - 将 jquery 数组附加到表单提交

google-app-engine - 部署在 Google App Engine 上的测试服务器

ios - 桌面和 iPad 横向混合媒体查询

ruby-on-rails - HTTP::Request::UnsupportedSchemeError -- Rails -- HTTP gem

PHP HTTP_User_Agent,将访问者重定向到移动页面,网站性能下降

c# - C# .NET 中的异步 POST 请求