I am trying to upload file to server location which is like this :
urlString : http://uploads.myLocation.com
Its is coming up as status code 405 - which means "Method not allowed". Do I need PHP script as suggested on last answer of this link ? ios Upload Image and Text using HTTP POST
How do server understand what I am sending? Is it any work for me as an IOS developer or its server side issue?
class func uploadTask(urlString: String, withDataString : String) {
print("URL To Upload :(urlString)")
if let percentURL = urlString.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())
{
let url:NSURL = NSURL(string: percentURL)!
let session = NSURLSession.sharedSession()
let request = NSMutableURLRequest(URL: url)
request.HTTPMethod = "POST"
request.cachePolicy = NSURLRequestCachePolicy.ReloadIgnoringCacheData
let data = withDataString.dataUsingEncoding(NSUTF8StringEncoding)
print("Data Length :(data?.length)")
let task = session.uploadTaskWithRequest(request, fromData: data, completionHandler:
{
(data,response,error) in
if error == nil
{
print("Response :(response)")
let httpResponse = response as! NSHTTPURLResponse
let statusCode = httpResponse.statusCode
print("Status Code: (statusCode)")
}
else
{
print("Error Uploading Data :(error)")
}
}
);
task.resume()
}
}
Aucun commentaire:
Enregistrer un commentaire