NSData *myRequest = [NSString stringWithFormat:(#"&site=%#&key=%#",tmpSite,tmpKey)];
Why is this not working ?
Thanks
Problem is that you are assigning NSString instance to variable of NSData type. Try this:
NSString* s = [NSString stringWithFormat:#"&site=%#&key=%#",tmpSite,tmpKey];
NSData* d = [s dataUsingEncoding:NSASCIIStringEncoding]; //or any other encoding!
NSData *myRequest = [[NSString stringWithFormat:(#"&site=%#&key=%#",tmpSite,tmpKey)] dataUsingEncoding: NSASCIIStringEncoding];
You can't just mix the two classes like that.
Related
I tried this way but it's not working.
This is the url to convert to base 64
NSString *strUrlB64 = [NSString stringWithFormat:#"https://play.google.com/store/apps/details?id=com.ShiftSharerfree_new&feature=search_result#?t=W251bGwsMSwyLDEsImNvbS5TGlmdFNoYXJlcmZyZWVfbmV3Il0"];
NSData *dataUrl = [NSData dataFromBase64String:strUrlB64];
Then tried to send this to another url.
NSString *urlStr = [NSString stringWithFormat:#"http://server39.pnht.com/360ad/apps/ads/%#/android/136/ord0.910950258132325?json=1&package_url=%#",self.mStrPid, dataUrl];
It is giving me output: NSString *urlStr = [NSString stringWithFormat:#"http://server39.pbgs.com/360ads/apps/ad/%#/android/1360/ord0.910950252132325?json=1&package_url=%#",self.mStrPid, url];
It is not base 64. please guide how to get base 64 out of it.
I am using base 64 to encode and decode some text,
can u tell me if it works with URLs,
- (NSString *)base64Encode:(NSString *)plainText
{
NSData *plainTextData = [plainText dataUsingEncoding:NSUTF8StringEncoding];
NSString *base64String = [plainTextData base64EncodedString];
return base64String;
}
- (NSString *)base64Decode:(NSString *)base64String
{
NSData *plainTextData = [NSData dataFromBase64String:base64String];
NSString *plainText = [[NSString alloc] initWithData:plainTextData encoding:NSUTF8StringEncoding];
return plainText;
}
I am having an issue while trying to convert NSString to NSData and vice versa.
I am trying to store encrypted string to my database. For that I am using AES algorithm. Now what I am doing is I get encrypted NSData and I am converting this to NSString using following:
// Not woking
NSString *strTemp = [[NSString alloc] initWithData:encData encoding:NSUTF8StringEncoding];
// Working
NSString *strTemp = [[NSString alloc] initWithData:encData encoding:NSASCIIStringEncoding];
Why NSData is not converting while using NSUTF8StringEncoding. Same way when I try to convert the string got by NSASCIIStringEncoding using:
// Not working
[strTemp dataUsingEncoding:NSASCIIStringEncoding];
// Working
[strTemp dataUsingEncoding:NSUTF8StringEncoding];
Why NSASCIIStringEncoding is not working while converting the NSString to NSData?
NSString to NSData:
NSString* str= #"teststring";
NSData* data=[str dataUsingEncoding:NSUTF8StringEncoding];
NSData to NSString:
NSString* newStr = [[NSString alloc] initWithData:theData
encoding:NSUTF8StringEncoding];
Please mind that NSASCIIStringEncoding and NSUTF8StringEncoding need to match the characters in the string.
I want to convert one NSString to NSData. on Using encoding am getting different value in NSData by displaying it using its description property.
I have
NSString *str=#"80369F4";
NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
on printing [data description]; am getting some different values...
how to extract the same string from the NSData.. pl help me out on this problem.
Create a new NSString:
NSString *newString = [[[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding] autorelease];
You can use NSString's initWithData:encoding: method:
NSString *str=#"80369F4";
NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
NSString *sameString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
This is the string I need to post http://www.mysite.com/save?details={"name"}
Iam trying the following code;
NSString *post =[NSString stringWithFormat:#"details={\"name\"}"];
NSString *hostStr = #"http://www.mysite.com/save?";
hostStr = [hostStr stringByAppendingString:post];
NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr]];
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
but the serverOutput always = null, unless i do just {name}. but i need the qutoes in there :(
You should convert everythign to valid HTTP symbols.
e.g.:
hostStr = [hostStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
...my guess is that your webserver is refusing your invalid URL.
wrong ..
NSString *post =[NSString stringWithFormat:#"details={\"name\"}"];
Correct:
NSString *post =[NSString stringWithString:#"details={\"name\"}"];
self.pdfPath = [[NSBundle mainBundle] pathForResource:#"iPhone_SDK_License" ofType:#"pdf"];
NSData *htmlData = [NSData dataWithContentsOfFile:pdfPath];
NSString *htmlstr = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];
It is showing nil in htmlstr, so need some assistance on it.
A pdf is not an html file so I assume that initWithData:encoding: just cannot understand the data and so fails.
Use stringWithContentsOfURL:encoding:error: to see the details of the error.