tags:

views:

23

answers:

2

Hello guys.

I make iphone application, post parametes to JSP (test.jsp in server) from iphone. The following is my codes:

NSData *postData = [@"&test=123&field=456" dataUsingEncoding:NSUTF8StringEncoding];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
// Init and set fields of the URLRequest
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setHTTPMethod:@"POST"];
[request setURL:[NSURL URLWithString:[NSString stringWithString:@"http://mydomain.com/test.jsp"]]];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

if (connection) {
// Return data of the request
NSData *receivedData = [[NSMutableData data] retain];
}

[request release];

But my problem is: I can not get return result from JSP server. How I can setup in JSP to get return result in iPhone? and in iPhone too?

Thank all

A: 

Do you implement this in your delegate:

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
Tuomas Pelkonen
what I have to setup in my JSP server ?
haicnpmk44
Tuomas Pelkonen
A: 

Data won't just magically appear in your receivedData instance. You need to implement the delegate methods for NSURLConnection. Take a look at Apple's documentation on how to this all properly.

Johan Kool