Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Curl 平方无效\u请求\u错误_Curl_Flutter_Dart_Square - Fatal编程技术网

Curl 平方无效\u请求\u错误

Curl 平方无效\u请求\u错误,curl,flutter,dart,square,Curl,Flutter,Dart,Square,我正在玩Flitter和Square Sandbox,并试图从应用程序中向信用卡收费 这是生成的cURL输出: curl --request POST https://connect.squareup.com/v2/locations/MY_LOCATION_ID/transactions \--header "Content-Type: application/json" \--header "Authorization: Bearer API_TOKEN" \--header "Accept

我正在玩Flitter和Square Sandbox,并试图从应用程序中向信用卡收费

这是生成的cURL输出:

curl --request POST https://connect.squareup.com/v2/locations/MY_LOCATION_ID/transactions \--header "Content-Type: application/json" \--header "Authorization: Bearer API_TOKEN" \--header "Accept: application/json" \--data '{"idempotency_key": "","amount_money": {"amount": 100,"currency": "USD"},"card_nonce": "cnon:CNONID"}'
但是我得到了这个错误:

{"errors":[{"category":"AUTHENTICATION_ERROR","code":"UNAUTHORIZED","detail":"This request could not be authorized."}]}
我插入了位置ID和API键,但这仍然是我得到的响应。知道为什么吗?我需要安装一些SSL证书吗

编辑

一段时间后,我尝试了以下方法:

String chargeServerHost = "http://192.168.178.35:8000";
String chargeUrl = "$chargeServerHost/buyCoins";

class ChargeException implements Exception {
  String errorMessage;
  ChargeException(this.errorMessage);
}

Future<void> chargeCard(CardDetails result) async {
  SharedPreferences prefs = await SharedPreferences.getInstance();
  String token = prefs.getString('token');

  var body = jsonEncode({"nonce": result.nonce, "token" : token});

  http.Response response;
  try {
    response = await http.post(chargeUrl, body: body, headers: {
      "Accept": "application/json",
      "content-type": "application/json"
    });
  } on SocketException catch (ex) {
    throw ChargeException(ex.message);
  }

  var responseBody = json.decode(response.body);
  print(responseBody.toString());

  if (response.statusCode == 200) {
    return;
  } else {
    throw ChargeException(responseBody["errorMessage"]);
  }
}

即使我现在有价值。。。这是卡片输入后生成的一些随机字符串。

您使用的是沙盒应用程序ID还是生产应用程序ID?与您的访问令牌对应的环境是否相同?当两者之间存在不匹配时,最终会出现此类错误。此外,如果要通过沙盒进行测试,请确保使用的是v1.2.3。我已经更新了我的问题。生成的字符串是否类似于
“cnon:CBASEEruNYMle5IA7LuxR8Ku1yZ”
?是的。我还尝试了
cnon:card nonce ok
并在我通过邮递员发送请求时工作,但不是从应用程序。
{errors: [{code: NOT_FOUND, detail: Card nonce not found, category: INVALID_REQUEST_ERROR}]}