how to place arabic in NSURLConnection - iphone

I have to put arabic in NSURLConnection, but the problem is that when I am not able to see arabic string properly using NSLog I get following string.
Country is الإمارات العربية المتحدة
and if I pass from NSURLConnection I get
http://xxxxxx.com/api/api.php?func=showAllCompaniesCategoriesCountryWise&params[]=الإمارات العربية المتحدة&params[]=all
bad URL
Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0x2f0b00 {NSUnderlyingError=0x2f1130 "bad URL", NSLocalizedDescription=bad URL}
So, please help me, how can I solve this problem.

You should use - (NSString *)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)encoding to create a proper string for NSURL.

Related

bad URL Connection Error

I am at my wits end with this one. I am attempting to make a connection to a website database. The URL I am using is: "https://subdomain.domain.com/scripts/script.php?v=YES&userid=xxxxxxxxxx&aid=yyyy&msg=test message"
Prior to sending the URL I encode the string as follows:
NSString *strURL = [url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
url = [url stringByReplacingOccurrencesOfString:#" " withString:#"%20"];
theURL = [NSURL URLWithString:strURL];
When I attempt to connect to the server I get the following error message:
NSLocalizedDescription = "bad URL";
NSUnderlyingError = "Error Domain=kCFErrorDomainCFNetwork Code=-1000 \"bad URL\" UserInfo=0xa11d760 {NSLocalizedDescription=bad URL
I cannot for the life of me figure out what is going on. Here are some of the actions I have taken to troubleshoot:
I have tested other URLs in the app encoded the same way and have no problem.
I entered the URL directly in Safari, Google and Mozilla with success.
When I tested the URL with curl in the Terminal I discovered the key-value pairs in the query where not being assigned, for example userid was null.
When I pasted escaped text into the curl command line the result was successful.
I do not know what to do here. Any thoughts are greatly appreciated!
I figured out the problem -- seems the URL set to the connection was not escaped properly. I passed the wrong string value to the method. As you can see in the code I passed URL instead of strURL.
Thanks for your help!

XMLParser error in objective c, Start tag expected, '<' not found?

in my application i tried to send a web service request in the NSString format. i used sudzc to generate web service . but, when i send the request, i got an error showing
Entity: line 1: parser error : Start tag expected, '<' not found
Bad Request
Error Domain=CXMLErrorDomain Code=1 "The operation couldn’t be completed. (CXMLErrorDomain error 1.)"^
here is my sending string which is in xml format,,
NSString *string=[NSString stringWithString:#"<request><ClosingDate>06-Sep-2012</ClosingDate><ProductName>Document Management Software</ProductName><ProductID>3</ProductID><CurrencyID>3</CurrencyID></request>"];
but the error shows '<' not found,
i dont know exactly what the error is?
need some help
EDIT
I USED SUDZC TO GENERATE WEB SERVICE
MFLCommonServices *services1=[MFLCommonServices service];
NSString *request=[NSString stringWithString:#"<request><ClosingDate>06-Sep-2012</ClosingDate><ProductName>Document Management Software</ProductName><ProductID>3</ProductID><CurrencyID>3</CurrencyID></request>"];
[services1 CreateRequest:self action:#selector(CreateRequestHandler:) Email:#"xxxxx" Password:#"xxxxxx" Token:#"xxxxxx" Request:request];

Objective C error 3840 - bad JSON apparently but it validates with JSlint

I have read around and this error seems to be from bad JSON. Easy enough, here is my JSON
{"year":"2012","wheels":"Standard","trans":"Unknown"}
My issue is, this appears to be correct, and when I run it through JSON lint it returns vaild. I have also used cURL to download this page and used json_decode() to read it...worked fine.
Here is an example page: http://drivingthenation.com/app/carlist/getVinDtn.php?v=JA3215H1C**M&f=v
I ran it through HTTPScoop and the only thing the response text returned was
{"year":"2012","wheels":"Standard","trans":"Unknown"}
On the objective-c end I am using NSURL and NSData to get the URL, and then NSJSONSerialization. I can print out before NSJSONSerialization and see that it is infact getting data, but this error only occurs when I try to format it into JSON. Any thoughts?
The NSJSONSerialization class, by default, expects the input to be not just valid JSON, but a valid JSON object. If you want to read something that's not an object, you need to specify the NSJSONReadingAllowFragments option to the reader.

Error while reading JSON url in nsstring

i am sending one url to the server
http://ogcitsco.w05.winhost.com/Service.svc/getsubmenu/south indian/restaurant/Lunch
in which i am getting bad url response, since there is one space between two words south indian, how should i work with that, i have tried to remove the space and passed the url however in response getting null value, when i paste the above url into browser it is showing the response
Remember to encode your URL first: [#"http://ogcitsco.w05.winhost.com/Service.svc/getsubmenu/south indian/restaurant/Lunch" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
a space can be changed to %20 for most languages (or + is possible too i beleve)

I am implementing Paypal and i have used this Soap message can anyone tell me where i am wrong?

NSString *parameterString = [NSString stringWithFormat:#"USER=username"
"&PWD=API Password"
"&SIGNATURE=API Signature"
"&METHOD=DoDirectPayment"
"&CREDITCARDTYPE=%#"
"&ACCT=%#"
"&EXPDATE=%#"
"&CVV2=123"
"&AMT=%#"
"&FIRSTNAME=%#"
"&LASTNAME=%#"
"&STREET=%#"
"&CITY=%#"
"&STATE=%#"
"&COUNTRY=%#"
"&ZIP=%#"
"&COUNTRYCODE=US"
"&PAYMENTACTION=sale"
"&VERSION=2.3",
txtCreditCardType.text,txtAccountNumber.text,txtExpireDate.text,txtTotalAmount.text,txtFirstName.text,txtLastName.text,txtStreet.text,txtCity.text,txtState.text,txtCountry.text,txtZip.text];
Maybe you need to properly url encode the values? Like the space in "API Password". The text in the text fields should also probably be url encoded instead of using the raw values.