如何使用Swift语言将文件发送到服务器?我将文件发送到服务器,并且全局变量$ _FILES(PHP)看不到下载的文件。在这种情况下,如果我从其他任何发件人程序包(例如ARC)发送请求。然后,全局阵列通过文件方法成功显示了传输的POST。怎么了??
outliers_df= pd.DataFrame(data)
outliers = outliers_df[db.labels_==-1]
这是创建请求正文的函数
// SEND DATA
let boundary = "--------------------------684819564013531921146535"
data = AppDelegate.createBody(boundary: boundary,
data: data,
mimeType: "image/png",
filename: "FF4D00-0.8.png")
let headers = [
"Content-Type":"multipart/form-data; boundary=\(boundary)",
"Content-Length":"\(data.count)"
]
HttpURLConnection.request(type: 1, command: "upload/img", headers: headers, body: data, complition: { (error, data) in
if error == nil && data != nil {
print(data)
}
})
这是工作:
答案 0 :(得分:0)
我正在使用Alamofire库。有据可查,例如:
let imageData = UIImagePNGRepresentation(image)!
Alamofire.upload(imageData, to: "https://httpbin.org/post").responseJSON { response in
debugPrint(response)
}