没有收到http请求响应

时间:2019-06-18 15:10:16

标签: nativescript

我正在尝试从php文件获得响应,但什么也没得到。

这是我编写的用于读取数据的http函数。该网址是真实的,可以根据需要进行测试。

exports.generate_cheksum = function () {
    console.log("generate_cheksum");

    const httpModule = require("http");
    httpModule.request({
        url: "http://tvastru.byethost7.com/paytm/generate_cheksum.php",
        method: "POST",
        headers: { "Content-Type": "application/json" },
        content: JSON.stringify({
        })
    }).then((response) => {
        console.log(response); //[object Object]
    }, (e) => {
        console.log("----error");
        console.log(e);
    });
}
<?php

    require_once("encdec_paytm.php");

    define("merchantMid", "V********************3");
    // Key in your staging and production MID available in your dashboard
    define("merchantKey", "0***************R");

    // Key in your staging and production merchant key available in your dashboard
    define("orderId", "order1");
    define("channelId", "WEB");
    define("custId", "cust123");
    define("mobileNo", "7777777777");
    define("email", "username@emailprovider.com");
    define("txnAmount", "100.12");
    define("website", "WEBSTAGING");
    // This is the staging value. Production value is available in your dashboard
    define("industryTypeId", "Retail");
    // This is the staging value. Production value is available in your dashboard
    define("callbackUrl", "https://<Merchant_Response_URL>");
    $paytmParams = array();
    $paytmParams["MID"] = merchantMid;
    $paytmParams["ORDER_ID"] = orderId;
    $paytmParams["CUST_ID"] = custId;
    $paytmParams["MOBILE_NO"] = mobileNo;
    $paytmParams["EMAIL"] = email;
    $paytmParams["CHANNEL_ID"] = channelId;
    $paytmParams["TXN_AMOUNT"] = txnAmount;
    $paytmParams["WEBSITE"] = website;
    $paytmParams["INDUSTRY_TYPE_ID"] = industryTypeId;
    $paytmParams["CALLBACK_URL"] = callbackUrl;
    $paytmChecksum = getChecksumFromArray($paytmParams, merchantKey);
    $transactionURL = "https://securegw-stage.paytm.in/theia/processTransaction";
    // $transactionURL = "https://securegw.paytm.in/theia/processTransaction"; // for    production

    echo json_encode($paytmChecksum);
?>

我测试过的php文件工作正常。我只希望生成校验和作为响应。

2 个答案:

答案 0 :(得分:1)

您需要做的事情

  1. 指向正确的URL。 (http://tvastru.byethost7.com/paytm/generate_checksum.php
  2. 您必须在Android.manifest文件中显式设置cleartextTrafficPermitted(android:usesCleartextTraffic =“ true”)。
  3. //响应的Content属性是HttpContent // toString方法允许您以字符串形式获取响应主体。 .then((response) => {console.log(response); //[object Object]}
  4. 从App调用您的php代码时,它返回This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support可能与您的代码无关,请检查您的托管服务。

答案 1 :(得分:1)

主要问题是Byet Host实现了一个简单的安全性反机器人模块>名为testcookie-nginx-module https://kyprizel.github.io/testcookie-nginx-module/

这很可能是服务器上的机器人保护插件。如果您可以控制服务器插件,则应禁用/删除它。如果它还是免费的托管服务商,则可能无法将其禁用。在这种情况下,此主机对您毫无用处,您应该搜索一个新的主机。

我使用我的paytm详细信息在服务器上测试了您的代码。一切正常