来自iOS的自定义HTTP请求被拒绝

来自iOS的自定义HTTP请求被拒绝,ios,swift,http,Ios,Swift,Http,我正在尝试向iOS上的php脚本发送HTTP请求。我使用多部分/表单数据,因为我还需要能够发送JPEG。用户代理curl每次都从终端works中的curl发送请求。下面是我根据下面的代码生成的请求 POST /Folder/GetData.php HTTP/1.1 Host: website_goes_here Content-Type: multipart/form-data; boundary=This12@ Expect: 100-continue Content-Length: 146

我正在尝试向iOS上的php脚本发送HTTP请求。我使用多部分/表单数据,因为我还需要能够发送JPEG。用户代理curl每次都从终端works中的curl发送请求。下面是我根据下面的代码生成的请求

POST /Folder/GetData.php HTTP/1.1
Host: website_goes_here
Content-Type: multipart/form-data; boundary=This12@
Expect: 100-continue
Content-Length: 146
Accept: */*
User-Agent: curl/7.37.1
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: keep-alive


--This12@
Content-Disposition: form-data; name=uname

ThisIsTheUserNameHere
--This12@
Content-Disposition: form-data; name=pass

PasswordGoesHere
--This12@--
以下是我用于生成此请求的swift代码(数据是一个变量,通过字典数组发送到函数):

发生的情况是,我的GoDaddy网站在最初几次返回有效响应,然后连接在下一分钟开始重置,并重复此操作。这有什么原因吗?请回复更正代码或HTTP请求。如果这有帮助,将通过以下方式发送连接:

NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) { (response, data, error) ->
        Void in
println(NSString(data: data, encoding: NSASCIIStringEncoding));
}

谢谢,

您没有显示实际发送请求和处理响应的代码


我猜你没有读到回应的结尾,所以连接没有被关闭。这将使您有很多连接保持打开状态,直到GoDaddy决定限制您。

结果表明,GoDaddy在一定时间内每个ip都有一个post限制。共享托管计划有一个限制

我如何才能关闭连接?我在问题中添加了我的代码。我认为
NSURLConnection.sendAsynchronousRequest
可以帮您完成这项任务。这个理论到此为止。对不起,我没主意了,还是谢谢你。我发现了下面的问题。
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) { (response, data, error) ->
        Void in
println(NSString(data: data, encoding: NSASCIIStringEncoding));
}