什麼是好的,在C#中簡單的談到了將在目標C熊C#HttpWebRequest的POST到Objective-C NSMutableURLRequest的StatusCode 405
static private void AddUser(string Username, string Password)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri("http://192.168.1.10:8080/DebugUser?userName=" + Username + "&password=" + Password));
request.Method = "POST";
request.ContentLength = 0;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Console.Write(response.StatusCode);
Console.ReadLine();
}
工作正常,但是當我試圖將其轉換爲Objective- C(IOS),我得到的只是「連接狀態405方法不允許」
-(void)try10{
NSLog(@"Web request started");
NSString *user = @"[email protected]";
NSString *pwd = @"myEazyPassword";
NSString *post = [NSString stringWithFormat:@"username=%@&password=%@",user,pwd];
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding];
NSString *postLength = [NSString stringWithFormat:@"%ld", (unsigned long)[postData length]];
NSLog(@"Post Data: %@", post);
NSMutableURLRequest *request = [NSMutableURLRequest new];
[request setURL:[NSURL URLWithString:@"http://192.168.1.10:8080"]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if(theConnection){
webData = [NSMutableData data];
NSLog(@"connection initiated");
}
}
任何幫助或指示在IOS上使用POST將是一個很大的幫助。
用戶名,用戶名中objC。在objC中使用小寫n可以嗎? –
另外,你的objC代碼不包含對DebugUser的引用,你發佈到/ –