Nativescript 无法获取http请求响应

Nativescript 无法获取http请求响应,nativescript,Nativescript,我试图从一个php文件中获取响应,但没有得到任何结果 这是我为读取数据而编写的http函数。url是真实的,如果需要,可以进行测试 exports.generate_cheksum = function () { console.log("generate_cheksum"); const httpModule = require("http"); httpModule.request({ url: "http://tvastru.byethost7.c

我试图从一个php文件中获取响应,但没有得到任何结果

这是我为读取数据而编写的http函数。url是真实的,如果需要,可以进行测试

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文件运行良好,我已经测试过了。我只想将校验和作为响应生成。

您需要做的几件事

指向正确的URL。 必须在android.manifest文件中显式设置ClearTextTrafficAllowed android:usesCleartextTraffic=true。 //响应的内容属性是HttpContent //toString方法允许您以字符串形式获取响应主体。 .thenresponse=>{console.logresponse;//[object]} 当您的php代码从应用程序调用时,它返回此站点需要Javascript才能工作,请在您的浏览器中启用Javascript或使用具有Javascript支持的浏览器,该浏览器可能与您的代码无关,请检查您的托管服务。
主要问题是Byet主机实现了一个名为testcookie nginx module>的简单安全反机器人程序模块

这很可能是服务器上的机器人保护插件。如果你可以控制你的服务器插件,你应该禁用/删除它。如果它也是一个免费的主机,你可能无法禁用它。在这种情况下,这个主人对你来说是无用的,你应该寻找一个新的主人


我用我的paytm详细信息在我的服务器上测试了你的代码。它工作正常

我不认为URL仍然有效-,它返回404。正如@Manoj提到的,URL不是valid@Narendra你真的在浏览器上运行URL了吗。我在浏览器窗口上收到一条校验和的回音信息,上面写着“404!”!我们找不到那一页。请检查以确保键入的URL正确。此Web服务器区分大小写,因此请确保URL中的大写字母与上载的文件匹配。`可能是您在etc/host文件中将该域配置为您的本地主机。我认为免费托管服务是导致此问题的原因。我很快就会买一个。
<?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);
?>