您好,我是在新的IOS,我並沒有發送任何調用到PHP到現在今天我有下面的代碼試圖HTTP POST請求
-(void)sendRequest
{
NSString *vali = @"$uppl!3r$";
NSString *post = [NSString stringWithFormat:@"key1=%@",vali];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSLog(@"%@",postLength);
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"http://www.ddemo3.enerjinet.com/webservices/ios/suppliers.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[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] retain];
NSLog(@"%@",webData);
}
else
{
}
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[webData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[connection release];
[webData release];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *loginStatus = [[NSString alloc] initWithBytes: [webData mutableBytes] length: [webData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@",loginStatus);
//greeting.text = loginStatus;
[loginStatus release];
[connection release];
[webData release];
}
它應該返回我的76條記錄陣列,但它返回我<>
任何人都可以請幫我嗎?該網站的服務好了,我需要得到響應的陣列,並顯示在我的表視圖,請幫我做這個
使用'initWithData:編碼:'創建字符串來自數據。 – Wain
我已添加nslog,它會轉到didfailwitherror爲什麼? @Wain – user3089900
我現在加了它,並且我得到了''''和那個ns日誌msg讓我試試你的曾經@Rob – user3089900