0

I wish to send a very very long string(length of string is more than 10000) to the server and in return get the jSON response from the string.What is the best approach for the task. I am sending various parameters along with this very very long string.

5
  • yes. Some thing as key-value combination
    – onkar
    Nov 26, 2012 at 7:28
  • Why do you think the string length matters at all? Nov 26, 2012 at 7:28
  • @EmilVikström I am trying to send it via myrequest/&lonstring= it is breaking up my data
    – onkar
    Nov 26, 2012 at 7:30
  • Use ASIFormDataRequest for sending the long string to the server
    – aViNaSh
    Nov 26, 2012 at 7:52
  • @aViNaSh any sample code/snippet ?
    – onkar
    Nov 26, 2012 at 7:55

3 Answers 3

1

Split down your long string to parts which can be send over one request. Create a json like this

 {
    "index":"0",
    "length":"LENGTH_OF_STRING",
    "string":"xsfsffwff.......",
    //other json parameters
 }

then you can send your string

0
1

The problem is that you're trying to put this all into a query parameter. Most servers have built-in limits for URLs, and for good reason.

There's nothing special about the body of an HTTP POST, so just send that up like you would anything else. Just make sure that you set the Content-Length header (since you know that; it might be covered by the HTTP library) and then just stream your data up. No need for any encoding or query params.

I don't know much about objective-c, but I'm sure there's a way to send data like this in an HTTP POST very simply. I've done this with Go and node.js, and both have simple ways of sending arbitrary data in a POST request body.

1
If you are using the ASI-Http classes , then you can send request like this
  ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:[WebService getAddPhoto]]];
                 [request addPostValue:[[imgArray objectAtIndex:i] valueForKey:@"vComments"] forKey:@"comment"];
                 NSData *imageData = UIImagePNGRepresentation([UIImage imageWithContentsOfFile:[[imgArray objectAtIndex:i] valueForKey:@"vPhoto"]]);
                 NSString *encodedString = [imageData base64EncodingWithLineLength:[imageData length]];
                 [request addPostValue:encodedString forKey:@"Photo"];
                 [request setDelegate:self];
                [request startAsynchronous]
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.