【问题标题】:iOS: failed socket-flow with Spring BootiOS:使用 Spring Boot 失败的套接字流
【发布时间】:2017-08-31 08:46:40
【问题描述】:

背景
我想使用 Alamofire 库将一个 base64 字符串从 iOS 应用程序发送到 Spring Boot 后端。

问题
它失败并出现此错误:

2017-08-31 10:22:49.547259+0200 Epic[851:367066] [] 
nw_endpoint_flow_prepare_output_frames [6.1 46.30.215.94:80 ready 
socket-flow (satisfied)] Failed to use 1 frames, marking as failed
2017-08-31 10:22:49.549173+0200 Epic[851:367066] [] 
nw_endpoint_handler_add_write_request [6.1 46.30.215.94:80 failed 
socket-flow (satisfied)] cannot accept write requests
2017-08-31 10:22:49.552773+0200 Epic[851:367069] [] 
tcp_connection_write_eof_block_invoke Write close callback received 
error: [22] Invalid argument

当我将端点从本地开发环境更改为 Heroko 时,出现了这个问题。 (http://heroku.com)。

我可以毫无问题地发送较小的图像 (100x100),但不能发送 (600x600)。

我试过了:
- 添加http头“Content-Length”和json正文的长度。
- 从发送 json 正文更改为 URL 参数。

有什么建议吗?我可以配置 heroku spring boot 以接受更大的 http 数据请求,还是需要在应用程序中进行设置?

我的代码:

func createImage(_ image: UIImage, success: @escaping (String)->(), failed: @escaping (Void)->(Void)){
    let base64 = image.getImageAsBase64()
    Alamofire.request(self.url, method: .put, parameters: ["image" : base64], headers: self.headers)
        .responseString(completionHandler: {response in
            switch(response.result) {
            case .success(let response):
                success(response)
                break;
            case .failure(let error):
                print(error)
                failed()
                break;
            }
        })
}

【问题讨论】:

    标签: ios xcode spring heroku alamofire


    【解决方案1】:

    有同样的问题。这是因为 Alamofire.request 的字符数是有限的。对于图像或大数据,您需要使用 Alamofire.upload。见https://github.com/Alamofire/Alamofire#uploading-data-to-a-server

    【讨论】:

      猜你喜欢
      • 2017-12-31
      • 1970-01-01
      • 2023-03-18
      • 2020-08-24
      • 2018-10-09
      • 2017-07-10
      • 2019-01-03
      • 1970-01-01
      • 2022-08-02
      相关资源
      最近更新 更多