0
如何將HTTP POST請求發佈到PHP服務器,並將註冊詳細信息加密爲HTTP參數。你能爲我的要求提供一個示例代碼嗎?向PHP服務器發送HTTP POST請求,並將註冊詳細信息加密爲HTTP參數
如何將HTTP POST請求發佈到PHP服務器,並將註冊詳細信息加密爲HTTP參數。你能爲我的要求提供一個示例代碼嗎?向PHP服務器發送HTTP POST請求,並將註冊詳細信息加密爲HTTP參數
您可以使用ASIHTTPRequest
,你可以這樣說:
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:someUrl];
[request setRequestMethod:@"POST"];
[request setPostValue:@"..." forKey:@"user"];
[request setPostValue:@"..." forKey:@"password"];
[request setDelegate:self];
[request startAsyncrhonous];
有委託方法對於像請求請求完成或失敗,因爲
- (void)requestFinished:(ASIHTTPRequest *)request
{
NSLog(@"Response %d ==> %@", request.responseStatusCode, [request responseString]);
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
NSLog(@"Response %d ==> %@", request.responseStatusCode, [request responseString]);
}
您可以隨時下載ASIHTTPRequest並能任何進一步的幫助,請訪問documentation。
希望這會有所幫助!
NSURL *url = [NSURL URLWithString:@"http://xyz"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
NSString *req;
req = [NSString stringWithFormat:@"Name=%@&Password=%@",userName,pass];// userName and pass are string
[request setHTTPMethod:@"POST"];
[request setHTTPBody: [req dataUsingEncoding:NSISOLatin1StringEncoding]];
NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:self];
[connection start];
下面是一個委託,它將帶來數據
-(void)connection:(NSURLConnection*)connection didReceiveData:(NSData *)data
{
NSError *erro;
NSDictionary *jsonData = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&erro];
NSLog(@"your data in dictionary is = %@",jsonData);
}
希望這將幫助你!