如何在axios请求中转换curl请求

时间:2018-05-31 21:48:42

标签: javascript reactjs http curl react-native

我有HTTP卷曲请求,但我不知道如何将其转换为axios请求。

CURL

curl -H 'User-Agent: Dalvik/2.1.0 (Linux; U; Android 6.0.1; SM-G900F Build/MMB29M)' -H 'Content-Type: application/json;arset=UTF-8' -H 'Host: reiseauskunft.bahn.de' --data-binary '{"auth":{"aid":"n91dB8Z77MLdoR0K","type":"AID"},"client":{"id":"DB","name":"DB Navigator","os":"Android 6.0.1","res":"1080x1920","type":"AND","ua":"Dalvik/2.1.0 (Linux; U; Android 6.0.1; SM-G900F Build/MMB29M)","v":18040000},"ext":"DB.R18.04.a","formatted":false,"svcReqL":[{"cfg":{"polyEnc":"GPA","rtMode":"HYBRID"},"meth":"TripSearch","req":{"outDate":"20180531","outTime":"204603","arrLocL":[{"crd":{"x":9684169,"y":50554794},"extId":"8000115","lid":"A=1@O=Fulda@X=9683980@Y=50554722@U=80@L=008000115@B=1@p=1525745008@","name":"Fulda","type":"S"}],"depLocL":[{"crd":{"x":13386988,"y":52520501},"extId":"8096003","lid":"A=1@O=BERLIN@X=13386988@Y=52520501@U=80@L=008096003@B=1@p=1526433964@","name":"BERLIN","type":"S"}],"getPasslist":true,"getPolyline":true,"jnyFltrL":[{"mode":"BIT","type":"PROD","value":"11111111111111"}],"trfReq":{"cType":"PK","jnyCl":2,"tvlrProf":[{"type":"E"}]}}}],"ver":"1.15"}' --compressed 'https://reiseauskunft.bahn.de/bin/mgate.exe?checksum=6d6fa2fac99949c118a40baf411875a0'

AXIOS

   axios(
    { 
    method: 'POST', 
    url: 'https://reiseauskunft.bahn.de/bin/mgate.exe?checksum=6d6fa2fac99949c118a40baf411875a0', 
    headers:  {
        'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 6.0.1; SM-G900F Build/MMB29M)',
        'Content-Type': 'application/json;charset=UTF-8',
        'Host': 'reiseauskunft.bahn.de'
    }, 
    data:  {"auth":{"aid":"n91dB8Z77MLdoR0K","type":"AID"},"client":{"id":"DB","name":"DB Navigator","os":"Android 6.0.1","res":"1080x1920","type":"AND","ua":"Dalvik/2.1.0 (Linux; U; Android 6.0.1; SM-G900F Build/MMB29M)","v":18040000},"ext":"DB.R18.04.a","formatted":false,"svcReqL":[{"cfg":{"polyEnc":"GPA","rtMode":"HYBRID"},"meth":"TripSearch","req":{"outDate":"20180531","outTime":"204603","arrLocL":[{"crd":{"x":9684169,"y":50554794},"extId":"8000115","lid":"A=1@O=Fulda@X=9683980@Y=50554722@U=80@L=008000115@B=1@p=1525745008@","name":"Fulda","type":"S"}],"depLocL":[{"crd":{"x":13386988,"y":52520501},"extId":"8096003","lid":"A=1@O=BERLIN@X=13386988@Y=52520501@U=80@L=008096003@B=1@p=1526433964@","name":"BERLIN","type":"S"}],"getPasslist":true,"getPolyline":true,"jnyFltrL":[{"mode":"BIT","type":"PROD","value":"11111111111111"}],"trfReq":{"cType":"PK","jnyCl":2,"tvlrProf":[{"type":"E"}]}}}],"ver":"1.15"}
}).then(response){
    console.log('===========response=========================');
    console.log(response);
    console.log('====================================');
}

它不起作用。有人知道为什么吗?我得到一个空数组的响应

0 个答案:

没有答案