2017-09-01 33 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

我嘗試了,但仍然沒有迴應 –

回答