0

I have an path:

file:////var/mobile/Containers/Data/Application/5421D684-D466-44F1-AEF5-7390598B5647/Documents/2016-07-29-17-00-12-0.MOV

By using this path i want to post my video using the below API:

139.162.12.178/mediaone/sample/instagram.php?url=<image_path>&image_name=<image_id>

Please help me out .

1 Answer 1

2

Sending POST requests in iOS is quite easy; and there's no need for an additional framework.


POST Request:

We begin by creating our POST's body (ergo. what we'd like to send) as an NSString, and converting it to NSData.

NSString *post = [NSString stringWithFormat:@"test=Message&this=isNotReal"];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

Next up, we read the postData's length, so we can pass it along in the request.

NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

Now that we have what we'd like to post, we can create an NSMutableURLRequest, and include our postData.

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://YourURL.com/FakeURL"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];

And finally, we can send our request, and read the reply by creating a new NSURLSession:

NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
[[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
    NSString *requestReply = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
    NSLog(@"requestReply: %@", requestReply);
}] resume];
Sign up to request clarification or add additional context in comments.

7 Comments

Thanks for the quick responce i have to customize my api
i have an out put i.e video recored video url and every time i record video the video name changes with time stamp. it is like instagram app
Request Data are not same every-time only parameter names are same
- (void)saveRecordedFile:(NSURL *)recordedFile { dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async(queue, ^{ ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init]; [assetLibrary writeVideoAtPathToSavedPhotosAlbum:recordedFile completionBlock: ^(NSURL *assetURL, NSError *error) { dispatch_async(dispatch_get_main_queue(), ^{ NSString *title; NSString *message; NSLog(@"%@",recordedFile); }); }];
recordedFile her i am getting out put and the out put is file:////var/mobile/Containers/Data/Application/5421D684-D466-44F1-AEF5-7390598B5647/Documents/2016-07-29-17-00-12-0.MOV i want to use this out put in the api
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.