2017-09-01 34 views
0

我必须通过表单数据正文部分。这里是邮递员屏幕短为更好的理解。 身体部位 enter image description here目标C中的POST表单数据C

内容类型

enter image description here

这里是我的代码是什么我不得不尝试。

NSString *Accesstoken = [NSString stringWithFormat:@"Bearer %@",tokenInfo.access_token]; 

    // parameter is String object : "user_id=18&deal_id=218" 

    //NSDictionary *tmp = [[NSDictionary alloc] initWithObjectsAndKeys: 
        @"user_id", @"18487", 
        @"deal_id", @"218", 
        nil]; 

// NSError * errorr; // NSData * postdata = [NSJSONSerialization dataWithJSONObject:tmp options:0 error:& errorr];

[request setValue:Accesstoken forHTTPHeaderField:@"Authorization"]; 

[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; 

[request setHTTPMethod:@"POST"]; 

[request setValue:postLength forHTTPHeaderField:@"Content-Length"]; 

// NSData *postData = [parameter dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; 

NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]]; 

// [请求setHTTPBody:POSTDATA] ;; // [请求setHTTPBody:[参数dataUsingEncoding:NSUTF8StringEncoding]]; // [request setHTTPBody:[NSJSONSerialization dataWithJSONObject:@ {@“user_id”:@“18487”,@“deal_id”:@“218”} options:0 error:nil]];

以上代码我得到http状态码:404它的错误。当我在邮递员的尝试中,我得到了完美的401我想要的。请帮忙谢谢。

+0

而不是'parameter'像你一样,尝试'[要求setHTTPBody:[NSJSONSerialization dataWithJSONObject:@ {@ “USER_ID”:@ “18”, @“deal_id”:@“218”} options:0 error:nil]];'?此外,您将地址隐藏在顶部地址栏中,但不在左侧菜单中(FYI)。 – Larme

+0

我尝试了,但仍然没有回应 –

回答