Actually I want to created application of shortening URL , i have used GoDady by creating account at http://app.x.co/ But My URL doesnot get shorten.
This is my key
#define kGoDaddyAccountKey #"b201137c009311e6984efa163ee12fa9"
This is actually The method that do work for Shortening URL
- (IBAction)shortenURL:(id)sender
{
NSString *urlToShorten = self.webView.request.URL.absoluteString;
NSString *urlString = [NSString stringWithFormat:#"http://api.x.co/Squeeze.svc/text/%#?url=%#",kGoDaddyAccountKey,
[urlToShorten stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
shortURLData = [NSMutableData new];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
shortenURLConnection = [NSURLConnection connectionWithRequest:request
delegate:self];
}
But I get error like This.
Quite Interesting, Please Help.
Related
WKWebview Load request send 500 when the method set to Post. backend said that it is not even receiving the call. and it is sending a proper error when method is GET.
NSString *fullURL = _URL;
NSString *encodedStringUrl = [fullURL stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
NSURL *url = [NSURL URLWithString:encodedStringUrl];
NSMutableURLRequest *requestObj = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];
NSString * token = [NSString stringWithFormat:#"bearer %#", [UserDefaults getAccessToken]];
NSDictionary * header = #{#"Content-Type": #"application/x-www-form-urlencoded",
#"Authorization": token};
[requestObj setHTTPMethod:#"POST"];
[requestObj setAllHTTPHeaderFields:header];
[_webview loadRequest:requestObj];
is there any other way to load the request into WKWebView with Authorization header?
If you ever encounter this error with WKWebView POST requests. Please check the server configurations for URL Module Redirect/ SSL redirect/ Cross Domain (CORS) issues. there is nothing to do from Mobile end. I had to make this post because Web and android was working fine and only the iOS was giving this error.
I'm attempting to ping eBay's API using an HTTP request, however Xcode is giving me the following error
No known class method for selector stringWithFormat
What I want to do here is append whatever string is input in the searchField to the end of the url. What am I doing wrong? Appreciate any help!
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if (sender != self.nextButton) return;
if (self.searchField.text.length > 0) {
self.responseData = [NSMutableData data];
NSURLRequest *request = [NSURLRequest requestWithURL:
[NSURL stringWithFormat:#"http://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=***APP ID ****&OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.12.0&RESPONSE-DATA-FORMAT=JSON&callback=_cb_findItemsByKeywords&REST-PAYLOAD&sortOrder=PricePlusShippingLowest&paginationInput.entriesPerPage=3&itemFilter(2).paramName=Currency&itemFilter(2).paramValue=USD&itemFilter(3).name=ListingType&itemFilter(3).value=FixedPrice&keywords=%#", self.searchField.text]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
}
You first need to create a NSString containing the URL and then create an NSURL out of it.
NSString *urlString = [NSString stringWithFormat:#"http://example.com/",
self.searchField.text];
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=***APP ID ****&OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.12.0&RESPONSE-DATA-FORMAT=JSON&callback=_cb_findItemsByKeywords&REST-PAYLOAD&sortOrder=PricePlusShippingLowest&paginationInput.entriesPerPage=3&itemFilter(2).paramName=Currency&itemFilter(2).paramValue=USD&itemFilter(3).name=ListingType&itemFilter(3).value=FixedPrice&keywords=%#", self.searchField.text]]];
You were missing a step, NSURL does not have a method called stringWithFormat.
I have a few paramaters I want to pass to the URL when performing a GET
The method I use for building the URL is:
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL: baseURL];
NSString* url = #"http://pretendurl.com/something";
NSMutableURLRequest *request = [httpClient requestWithMethod: #"GET"
path: url
parameters: params];
Where params is an nsdictionary that has been populated.
This adds the parameters to the url file but it adds &format=json to the end of the URL.
I would like to know how to get it to build the URL without the last piece. I had a look through the AFNetworking source code but couldn't spot where it actually adds that bit.
Thanks in advance.
you could convert you dictionary params to query url using a function like this
-(NSString*) getQueryUrlFromDictionary:(NSDictionary*) dict usingUrlEncoder:(BOOL)makeUrlEncoded
{
if (dict == nil)
return #"";
NSMutableString* outputStr = [[NSMutableString alloc] initWithString:#""];
int px = 0;
for (NSString* key in dict) {
NSString* param = (NSString*) [dict objectForKey:key];
// using urlEncoding : look for NSString+URLEncoding.h implementation
if (makeUrlEncoded)
param = [param urlEncodeUsingEncoding:NSUTF8StringEncoding];
[outputStr appendFormat:#"%#=%#",key,param];
if ( px < ([dict count]-1 ) )
[outputStr appendString:#"&"];
px++;
}
return outputStr;
}
So ...
NSMutableURLRequest *request = [NSMutableURLRequest
requestWithURL: baseURL
cachePolicy: NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval: 60.f];
[request setHTTPMethod:#"GET"];
NSString* paramString = [self getQueryUrlFromDictionary:params usingUrlEncoder:YES];
NSData *postData = [paramString dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
[request setHTTPBody:postData];
I use something like this and works fine, hope it helps
for me everything should work fine, but try this:
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:"http://pretendurl.com"]];
NSMutableURLRequest *request = [httpClient requestWithMethod:#"GET"
path:#"something"
parameters:params];
I have a bit of a confusing situation. I have a form after which I create a url and make an asynchronous server call. That data does not need to be secure.
Here is what I have:
NSString *urlString = #"http://my.url.com/script_name.php?subject=hardcoded_string&body=";
NSString *inputString = textArea.text;
NSString *url_to_send = [NSString stringWithFormat:#"%#%#", urlString , inputString];
NSURL *url = [NSURL URLWithString:url_to_send];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url ];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
...
Is there something that I am doing incorrectly here in how I create the url?
Thanks!
it seems ok... take a look at asihttprequest libs, on google... that's a powerful wrapper for http connections... you should now set up the queue and add the request to the queue. finally you have to start the queue.
today, I encountered a problem with NSURLConnection. I want to download the contents of the URL http://api.wunderground.com/api/fs3a45dsa345/geolookup/q/34.532900,-122.345.json. If I simply paste the URL into Safari, I get the correct response. However, if I do the same thing with NSURLConnection, I get a "not found" response. Here's the code I'm using:
NSURL *requestURL = [[NSURL alloc] initWithString:#"same url as above"];
NSURLRequest *urlRequest = [[NSURLRequest alloc] initWithURL:requestURL];
NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest:urlRequest
delegate:self
startImmediately:YES];
What's the problem here?
Make sure you're escaping any special characters in the URL string by sending it a stringByAddingPercentEscapesUsingEncoding: message, for example:
NSString *s = [#"some url string" stringByAddingPercentEscapesUsingEncoding:NSUTFStringEncoding];
NSURL *requestURL = [NSURL URLWithString:s];
EDIT
It turns out the web service request is failing because the User-Agent header doesn't get set by default. To set it, use an instance of NSMutableURLRequest rather than NSURLRequest to create the request, as shown below:
NSMutableURLRequest *myRequest = [NSMutableURLRequest requestWithURL:myURL];
[myRequest setValue:#"My App" forHTTPHeaderField:#"User-Agent"];
Where is the delegate code? For async NSURLConnection there needs to be a delegate method to receive the returned data. Other options include sendSynchronousRequest: or if it must be async wrapping sendSynchronousRequest in a GCD block.