开发者

Passing html parameters to server odd problem

开发者 https://www.devze.com 2022-12-26 03:52 出处:网络
I am having a weird problem with sending data back to my server. This is the code I am using: NSString *theURL =[NSString stringWithFormat:@\"http://www.xxx.com/confirm.asp?theID=%@&theName=%@&am

I am having a weird problem with sending data back to my server. This is the code I am using:

   NSString *theURL =[NSString stringWithFormat:@"http://www.xxx.com/confirm.asp?theID=%@&theName=%@&empID=%@&theComp=%@", theConfirmNum, tmpNBUserRow.userName, labelTxt.text, theID];

   NSLog(@"%@,%@,%@,%@", theConfirmNum, tmpNBUserRow.userName, labelTxt.text, theID);

   NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
   [request setURL:[NSURL URLWithString:theURL]];
   [request setHTTPMethod:@"POST"];

   NSError *error;
   NSURLResponse *response;

   NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
   NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];

   if ([data isEqualToString:@"Done"])

I can run the code from the browser and it works just fine using th开发者_开发技巧e data i got from the NSLog output. The NSLog output for each value is correct. But for some reason when i put a break on:

if ([data isEqualToString:@"Done"]) 

...it has no return value. I checked each value for what it was sending (and again, it was correct in the NSLog output) and I found that the value "theID" said "Out of scope". Although, again, the NSLog had the value in it correctly?

So I searched the forum and found a simular problem. I took their advice and added "RETAIN" to the "theID" value like so:

theID = [customObjInstance TID];
[theID retain];

However, that did not solve the issue...

Here is the console NSLog output:

 [Session started at 2010-04-11 01:31:50 -0400.]
 wait_fences: failed to receive reply: 10004003
 wait_fences: failed to receive reply: 10004003
 nbTxt(5952,0xa0937500) malloc: *** error for object 0x3c0ebc0: double free
 *** set a breakpoint in malloc_error_break to debug
 2010-04-11 01:32:12.270 nbTxt[5952:207] 5122,Rob S.,5122,NB010203

The NSLog values I am sending is the last line "5122,Rob S.,5122,NB010203"

Any help would be great :o)

David


You should try this code after the send request to server. I think this should resolve your problem.

NSDictionary* json = nil;
 if (kivaData) {
   json = [NSJSONSerialization
            JSONObjectWithData:kivaData
            options:kNilOptions
            error:nil];
} 

NSLog(@"addfee %@",addfee);
 NSLog(@"JSON %@",json);
[NSString stringWithFormat:
postname=json[@"post_title"],
description=json[@"post_content"],
 sms=json[@"sms"],
 expire=json[@"expire"],
location=json[@"location"],
category=json[@"category"],
 smstext=json[@"sms"],
 totalcomments=json[@"totalcomments"],
warning=json[@"warning"],
 nil];


SOLVED!!!

It was all because of the space between the name "Rob S.". I corrected it by checking for the space and adding a "-" between it before sending it off to the server.

 NSString *tempUN = tmpNBUserRow.userName;
 tempUN = [tempUN stringByReplacingOccurrencesOfString:@" " withString:@"-"];

David


Take a look at stringByAddingPercentEscapesUsingEncoding: in NSString.

0

精彩评论

暂无评论...
验证码 换一张
取 消