views:

71

answers:

4

Hi friends,

I want to send the bytes to the server. So i donno Which data types is used for bytes. I have used "%s" and sent the bytes to the server. But In server side they have received 6 bytes only. But my case i want to send 32 bytes to the server. So Which data type is used for that?

EDIT:-

Here my sample code is,

 -(void)sendDevice:(NSData *)data // data value comes 32 bytes.
 {
       NSString *urlString = [NSString stringWithFormat: @"http://MyserverURL.php?Dataid=%????",[data bytes]];

       NSURL *urlToSend2 = [[NSURL alloc] initWithString:urlString];

       NSURLRequest *urlRequest2 = [NSURLRequest requestWithURL:urlToSend2              cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:50];                                                     

       NSURLConnection *theconnection=[[NSURLConnection alloc] initWithRequest:urlRequest2 delegate:self]; 

      [theconnection start];

 }

Please Guide me.

Thanks.

+1  A: 

NSData is the class that generally is used for byte data. take a look at its documentation and see if thats what you need.

Jesse Naugher
@Jesse Naugher,Thanks for the reply. I have used NSData and sent the bytes to the server. In my case, NSData value is [data bytes], How can i post to the server, NSString *urlString = [NSString stringWithFormat: @"http://InMy serverurl.com/DTid=%????",[data bytes]];
Pugal Devan
A: 

looks like you are trying to POST data to the server?

look at this question it might be similar and provide the answer

http://stackoverflow.com/questions/1571336/sending-post-data-from-iphone-over-ssl-https

Aaron Saunders
+1  A: 

As Jesse suggests, raw bytes are best stored in an NSData instance. For transmission to your web server, you'll probably want to create a Base64-encoded string representation of the NSData's bytes. For that, I recommend either of the categories present at the bottom of this CocoaDev wiki page.

Brad Larson
A: 

If you use arbitrary data, first hexify it and then use %s. On the server side you can decode it on reception. So basically do a repeated sprintf with format "%02x" and append these. In that case it will survive inside url-strings, after the ? as in your example.

Henno Brandsma
to comment on myself: I saw the Base64 suggestion below (which is more efficient) but I avoided it because the standard alphabet contains /,but I saw in the link you can specify your own, cool!
Henno Brandsma