小编Mam*_*mta的帖子

将图像上传到服务器 - Swift 3

我想将图像作为参数与我的请求一起发送.我使用下面的代码来调用我的POST请求,但我不知道如何将图像附加到正文.

我通过图像选择器获取图像如下:

if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
Run Code Online (Sandbox Code Playgroud)

我的要求如下

var request = URLRequest(url: URL(string: "")!) // link removed
        request.httpMethod = "POST"
        let postString = "user_id=\(userId)&image=\(image)"
        request.httpBody = postString.data(using:.utf8)

        let task = URLSession.shared.dataTask(with: request) { data, response, error in
            guard let data = data, error == nil else {               // check for fundamental networking error
                return
            }
            do {
                let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? AnyObject

                if let parseJSON = json {
                    print("resp :\(parseJSON)")
                }
            } …
Run Code Online (Sandbox Code Playgroud)

web-services image request ios swift

6
推荐指数
2
解决办法
3万
查看次数

Braintree - Drop-in UI - Apple Pay - Swift 3

我正在集成用于信用卡、贝宝和苹果支付的 Braintree Drop-in UI。我遵循了信用卡付款的基本步骤。在沙箱中一切正常。

现在我正在实施苹果支付。

我已经完成了这里提到的配置,成功:https : //developers.braintreepayments.com/guides/apple-pay/configuration/ios/v4

这是它现在在模拟器中的样子:

在此处输入图片说明

我编写了以下代码来实现信用卡支付:

import UIKit
import BraintreeDropIn
import Braintree

class DonationPaymentViewController: UIViewController {

let toKinizationKey = "my_tokenization_key"
@IBOutlet weak var amountTextField: UITextField!

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func sendRequestPaymentToServer(nonce: String, amount: String) {
    let paymentURL = URL(string: "my_api_url")!
    var request = URLRequest(url: paymentURL)
    print("paymentMethodNonce=\(nonce)&amount=\(amount)")
    //request.httpBody = "paymentMethodNonce=\(nonce)&amount=\(amount)".data(using: …
Run Code Online (Sandbox Code Playgroud)

paypal braintree ios swift applepay

4
推荐指数
1
解决办法
1906
查看次数

标签 统计

ios ×2

swift ×2

applepay ×1

braintree ×1

image ×1

paypal ×1

request ×1

web-services ×1