0

次のような形式の URL があります。

NSString *url1 = [NSString stringWithFormat:@"%@",http:abc.com/check?para1= 1,2,3,4,5,6,7,8...,1000&Param2= 1,2,3 ...,1000&Param3=12:12:12.000&Param4=1.12310&Param5=http:yahoo.com/adsf.html]

使用しています

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url1]];
    [request setHTTPMethod:@"POST"];
    [request setValue:[NSString stringWithFormat:@"%d", [url1 length]] forHTTPHeaderField:@"Content-length"];
    [request setValue:@"text/plain" forHTTPHeaderField:@"Content-type"];

    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [NSURLConnection connectionWithRequest:request delegate:self];
    
    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    NSString *responseString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
    NSLog(@"response - %@",responseString);

しかし、サーバーに送信できません。

4

2 に答える 2

1

コードを変更しました。これを試してください:

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSString *url1       = [NSString stringWithFormat:@"%@", @"para1= 1,2,3,4,5,6,7,8...,1000&Param2= 1,2,3...,1000&Param3=12:12:12.000&Param4=1.12310&Param5=http:yahoo.com/adsf.html"];
NSData *postData     = [url1 dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];    
NSString *postLength = [NSString stringWithFormat:@"%u", [postData length]];
[request setURL:[NSURL URLWithString:@"http:abc.com/check"]];
[request setHTTPMethod:@"POST"];
[request setValue:@"Close" forHTTPHeaderField:@"Connection"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"text/plain" forHTTPHeaderField:@"Content-type"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];    
NSData *returnData       = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *responseString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"response - %@",responseString);

お役に立てますように。

于 2013-06-16T11:26:31.633 に答える