【问题标题】:Prevent request timing out - large POST data防止请求超时 - 大型 POST 数据
【发布时间】:2012-07-06 21:50:14
【问题描述】:

在我的 iOS 应用程序中,为了发布新问题,我向 http://api.mysite.com/questions 发出 HTTP POST 请求。 POST 数据显然更大或更小,具体取决于图像是否附加到问题上。小(大小约为 100-200kb)图像可以毫无问题地发布到服务器。但是,来自设备相机的较大照片 (~1mb) 会导致请求超时,因为图像尺寸较大。

请您告诉我如何确保图片上传没有问题,这似乎不会发生在许多其他应用程序中。

是服务器的问题还是 iOS 代码本身的问题?

编辑----

在服务器上,一旦收到请求,PHP 就会将图像数据写入文件。 blob 是图像数据:

$filepath = $this->debug == true ? "../cityw/img/questions/{$qid}/attachment.png" :"../i/questions/$qid/attachment.png";

if (!file_exists($this->debug == true ? "../cityw/img/questions/{$qid}" : "../i/questions/{$qid}")) {
    mkdir($this->debug == true ? "../cityw/img/questions/{$qid}" : "../i/questions/{$qid}");
}

$fh = fopen($filepath, 'w');

fwrite($fh, $blob);
fclose($fh);

图像数据以 BASE64 格式发送到服务器,到达服务器后进行解码。

【问题讨论】:

  • 超时意味着服务器没有响应。你的服务器对数据做了什么?
  • 只是将其写入文件。我会更新问题
  • 你试过了吗:set_time_limit
  • 即使你的iOS应用程序超时,服务器是否也能成功写入文件?
  • set_time_limit 没试过,现在试试。

标签: php ios post httpwebrequest


【解决方案1】:

你试过用set_time_limit解决你的问题吗

很高兴这对你有用。

【讨论】:

    猜你喜欢
    • 2012-09-29
    • 1970-01-01
    • 2011-04-23
    • 2014-06-17
    • 2012-04-23
    • 2011-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多