Send data and parameter to server

风格不统一 提交于 2019-12-12 06:36:17

问题


I have this code here that send a data to my server, this code works very well:

NSString *imagepath = [[self applicationDocumentsDirectory].path stringByAppendingPathComponent:@"ProgrammingWithObjectiveC.pdf"];

    NSURL *outputFileURL = [NSURL fileURLWithPath:imagepath];

    NSURL *icyURL = [NSURL URLWithString:uploadURLString];

    NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:icyURL];

    [request setHTTPMethod:@"POST"];

    NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@"com.app.upload"];

    NSURLSession *upLoadSession = [NSURLSession sessionWithConfiguration:sessionConfig delegate:self delegateQueue:nil];

    self.uploadTask = [upLoadSession uploadTaskWithRequest:request fromFile:outputFileURL];

    [self.uploadTask resume];

As I say before, This code works very well, and the php file is:

<?php

 $fp = fopen("myImage.pdf", "a");

 $escreve = fwrite($fp, file_get_contents("php://input"));

 fclose($fp);

 ?>

The problem is that I need to send some parameters in POST method like filename, id, and others, I try many things to do this, but I could not anything.

Other Solution

Well I was thinking how to solve this problem, I can send data but without send parameters, I can send parameters but without send data, but I can't send these two in the same request.

In my case I would need to send one image and a name of this image to my server, so the first think is send a image to my server with that code showing up!

In php I get this file, and generate a ramdom and long name for him, and return this name to Objective-c.

When Objective-c receive this response he send another request with the name of the file and the name of the file that we receive from the server. And now PHP receive this request and change the name of the file with the right name.

来源:https://stackoverflow.com/questions/29577741/send-data-and-parameter-to-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!