Vimeo.com upload failure - objective-c

To have an ability to upload i have to get upload ticket. But after checking it looks like invalid.
After I create new ticket I check it and get the error 702. Please help. i've checked the parameters and they looks fine.
//vimeo.videos.upload.getTicket
NSURL *ticketRequestURL = [NSURL URLWithString:#"http://vimeo.com/api/rest/v2?format=json&method=vimeo.videos.upload.getTicket"];
NSMutableURLRequest *ticketRequest = [NSMutableURLRequest requestWithURL:ticketRequestURL];
[ticketRequest setHTTPMethod:#"POST"];
[auth authorizeRequest:ticketRequest];
[NSURLConnection sendAsynchronousRequest:ticketRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *ticketRequestResponse, NSData *ticketRequestData, NSError *ticketRequestError) {
NSString *ticketRequestResponseString = [[NSString alloc] initWithData:ticketRequestData encoding:NSStringEncodingConversionAllowLossy];
NSDictionary *d = [[parser objectWithString:ticketRequestResponseString] objectForKey:#"ticket"];
NSString *identifier = [d objectForKey:#"id"];
//vimeo.videos.upload.checkTicket
NSURL *ticketCheckRequestURL = [NSURL URLWithString:#"http://vimeo.com/api/rest/v2?format=json&method=vimeo.videos.upload.checkTicket"];
NSMutableURLRequest *ticketCheckRequest = [NSMutableURLRequest requestWithURL:ticketCheckRequestURL];
[ticketCheckRequest setHTTPMethod:#"POST"];
[ticketCheckRequest setValue:identifier forHTTPHeaderField:#"ticket_id"];
[auth authorizeRequest:ticketCheckRequest];
[NSURLConnection sendAsynchronousRequest:ticketCheckRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *ticketRequestResponse, NSData *ticketRequestData, NSError *ticketRequestError) {
NSString *ticketCheckRequestResponseString = [[NSString alloc] initWithData:ticketRequestData encoding:NSStringEncodingConversionAllowLossy];
NSLog(#"%#", ticketCheckRequestResponseString);
}];
}];

Hm... Specifying ticket_id in the URL solved my problem.
NSURL *ticketCheckRequestURL = [NSURL URLWithString:[NSString stringWithFormat:#"http://vimeo.com/api/rest/v2?format=json&method=vimeo.videos.upload.checkTicket&ticket_id=%#", identifier]];

Related

how to consume the json web service in objective c?

i am consuming the json webservice .i am assigning the stringurl to nsurl but the nsurl always assigning the null value. also i didn't get the response. can anyone suggest me what is the mistake i done in the following coding
- (IBAction)addbutton:(id)sender {
NSString *urltest = #"sample url";
NSURL *url = [NSURL URLWithString:urltest];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response,
NSData *data, NSError *connectionError)
{
if (data.length > 0 && connectionError == nil)
{
NSDictionary *greeting = [NSJSONSerialization JSONObjectWithData:data
options:0
error:NULL];
NSString *test= [[greeting objectForKey:#"code"] stringValue];
NSString *test1 = [greeting objectForKey:#"message"];
}
}];}
Your URL string is invalid, note the part:
taxName=ÂU.F¿Kåa¥gh
Those characters are not allowed in URL. Fix your URL to a valid URL (e.g. percent-encode parameter values).
E.g. the above with URL encoding would be:
taxName=%C3%82U.F%C2%BFK%C3%A5a%C2%A5gh
but I am not sure that's correct. The parameter value does not seem to be valid.
Please use this:
NSString *urlString = #"http://localhost:8080/MyWebservice.asmx/GetHelloWorldWithParam";
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod: #"POST"];
[request setValue:#"application/json" forHTTPHeaderField:#"Accept"];
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"Content-Type"];
NSString *myRequestString = #"param="; // Attention HERE!!!!
[myRequestString stringByAppendingString:myParamString];
NSData *requestData = [NSData dataWithBytes:[myRequestString UTF8String] length:[myRequestString length]];
[request setHTTPBody: requestData];
Thank you

Parse xml(from web service) to NSDictionary in objective c

I do synchronous post request and get xml. Now I need parse and save it in NSDictionary. I tried many solutions from the web. But nothing worked for me. Here's my code:
//Response data object
NSData *returnData = [[NSData alloc]init];
NSString *param = #"{params}";
NSString *postString = [NSString stringWithFormat:#"request=%#",param];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:#"url"]];
[request setHTTPMethod:#"POST"];
[request setValue:[NSString stringWithFormat:#"%lu", (unsigned long)[postString length]] forHTTPHeaderField:#"Content-length"];
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
//Send the Request
returnData = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil];
//Get the Result of Request
NSString *response = [[NSString alloc] initWithBytes:[returnData bytes] length:[returnData length] encoding:NSUTF8StringEncoding];
bool debug = YES;
NSDictionary *xmlDoc = [NSDictionary dictionaryWithXMLFile:response];
if (debug && response) {
NSLog(#"Response >>>> %#", xmlDoc);
}
I used this xml reader. Here is result which I get in nslog:
2016-11-28 18:04:26.970 SyncPostReq[8667:305923] Response >>>> (null)
NSURL *url = [NSURL URLWithString:#"url"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:#"POST"];
NSURLSession *session = [NSURLSession sharedSession];
[[session dataTaskWithURL:url
completionHandler:^(NSData *data,
NSURLResponse *response,
NSError *error) {
NSError *parseError;
NSDictionary* xmlDict1 = [XMLReader dictionaryForXMLData:data error:&parseError];
NSDictionary *dictData = [xmlDict1 objectForKey:#"event_listing"];
arrData = [dictData objectForKey:#"event"];
NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
[defaults setObject:arrData
forKey:#"Keyupevent"];
[defaults setBool:YES forKey:#"KeyalldataLoad"];
[defaults synchronize];
uparrData =[[defaults objectForKey:#"Keyupevent"] mutableCopy];
[arrStoreAllEventsData addObjectsFromArray:uparrData];
[self.tblView reloadData];
[self loadPastEventdatafromxml];
}] resume];

How to send json data in the Http request to POST Method in JSON Parsing

I need to Parse below string to POST method in iOS
"jsonData":{"empId":"cxvd","password":"sfsd"}
But I m getting the error as
Res: Tomcat Error
HTTP Status 400 - Required String parameter 'jsonData' is not present
//------ Method I have used to Parse is ---------- //
+(void) requestToServerForLogin:(NSString*)userName andPassward: (NSString*)password onCompletion:(RequestCompletionHandler) handler
{
NSString *url = [Ip stringByAppendingString:#"login"];
NSString *jsonString = [NSString stringWithFormat:#"\"jsonData\":{\"empId\":\"%#\",\"password\":\"%#\"}",
userName,
password ];
NSURL *nsurl = [NSURL URLWithString:url];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:nsurl];
[urlRequest setTimeoutInterval:60.0f];
[urlRequest setHTTPMethod:#"POST"];
[urlRequest setValue:#"application/json"
forHTTPHeaderField:#"Content-type"];
NSString *body = jsonString1;
[urlRequest setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(#"urlRequest :%#",[body dataUsingEncoding:NSUTF8StringEncoding]);
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:urlRequest
queue:queue
completionHandler:^(NSURLResponse *response,
NSData *data1, NSError *error)
{
NSString *res = [[NSString alloc] initWithData:data1 encoding:NSUTF8StringEncoding];
if(handler) handler(res,error);
}];
}
Thanks in advance
There is way to much code. The substringToIndex and substringFromIndex are wrong, should not be in the code.
Use the literal syntax for the dictionaries:
NSDictionary *jsonDict = #{#"jsonData":#{#"password":password, #"empId":userName}};
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict options:0 error:&error];

Can't POST a request to service

For some reason I always get Endpoint not found., but when I put it in the browser it works perfectly. I'm sure doing something wrong..
- (void)requestLoad:(NSString *)req_udid Age:(NSString *)req_age Gender:(NSString *)req_gender CheckBoxes:(NSString *)req_checkBoxes
{
NSString *post = [NSString stringWithFormat:#"/UpdatePersonalInterests/%#/%#/%#/%#/0",req_udid, req_age, req_gender, req_checkBoxes];
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
//set up the request to the website
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:NSLocalizedStringFromTable(#"kServiceURL", #"urls", nil)]];
[request setHTTPMethod:#"POST"];
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"Content-Type"];
[request setValue:[NSString stringWithFormat:#"%d", [postData length]] forHTTPHeaderField:#"Content-Length"];
[request setHTTPBody:postData];
NSError *error;
NSURLResponse *response;
NSData *urlData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *result = [[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(#"%#",result);
}
Thanks!
It looks like you are using a Custom Service scheme. Did you register it in Target -> info - URLS Types? See the Apple Docs or Registering custom URL Schemes: Implementing Custom URL Schemes
So I've managed to do this with NSURLConnection and asynchronous request with this code:
- (void)getIntrests
{
NSString *req_udid = [PROUtils createOrLoadUserIdentifier];
NSString *webaddress = [kServiceBaseURL stringByAppendingString:[NSString stringWithFormat:#"/GetPersonalInterestsForUdid/%#",req_udid]];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:webaddress] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:20];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:
^(NSURLResponse* response, NSData* data, NSError* error) {
NSString* dataString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
[[NSNotificationCenter defaultCenter] postNotificationName:kGotMediaFromServer object:dataString];
NSLog(#"Update response completed: %# with data: %# error: %#",response,dataString,error);
}];
}
Hope that it will be useful for someone.

iphone SDK: How to post data to a url?

This may be a duplicate question but i could not find my answer when searching. So, How do i post data to a url? Heres what i got so far:
NSString *url = #"https://localhost/login.php";
NSURL *urlr = [NSURL URLWithString:url];
NSMutableURLRequest *urlre = [[NSMutableURLRequest alloc] init];
[urlre setURL:[NSURL URLWithString:url]];
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
NSString *user = [defs stringForKey:#"User"];
NSString *pass = [defs stringForKey:#"Pass"];
NSInteger *version = [defs integerForKey:#"Version"];
NSString *bodyData = [[NSString alloc] initWithFormat:#"user=%#&password=%#&version=%d",user,pass,version];
NSData *body = [bodyData dataUsingEncoding:NSASCIIStringEncoding];
NSURLResponse *response = nil;
NSError *error = nil;
[urlre setHTTPMethod:#"POST"];
[urlre setValue:[[NSString alloc] initWithFormat:#"%d",[body length]] forHTTPHeaderField:#"Content-Length"];
[urlre setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"Content-Type"];
[urlre setHTTPBody:body];
NSData *dataThis = [NSURLConnection sendSynchronousRequest:urlre returningResponse:&response error:&error];
if(dataThis)
{
NSLog(#"Connect Success");
} else {
NSLog(#"%#",[error localizedDescription]);
}
Is the above correct? In my
-(void) connection:(NSURLConnection*)connection didReceiveData:(NSData *)data
event, I get nothing. Even in the didFinishLoading it gets nothing with NSLog. Please help.
Have you set a delegate for your request?
Why don't you have a look at using a framework like ASIHTTPRequest, makes things so simple. Check it out http://allseeing-i.com/ASIHTTPRequest/