drydaenth257216154 2014-03-22 23:09
浏览 240
已采纳

我的JSON字符串无法通过HTTP GET请求获得完整

when i send my array to my php file it incomplete recive to php file. my arr varible is :

[["╪▒┘à┘╛┘╪د","67126881188552864","Empty,Empty,Empty,Empty,8644,-360,-4,8691,-3
.48,-313,1015,4.334 M,1392/12/28,12:30:08,3.99 M,10 B,10%,530,16.4,16.38,┘à╪ش╪د╪
▓,7,3130,8644,1,50,5000, , , ,8644,11553,359,307,8645,1,1,8655,11
030,2,┌»╪▒┘ê┘ç ┘à┘╛┘╪د (╪│┘ç╪د┘à┘è ╪╣╪د┘à) (╪▒┘à┘╛┘╪د),╪ذ╪د╪▓╪د╪▒ ╪د┘ê┘ (╪ز╪د
╪ذ┘┘ê┘è ╪د╪╡┘┘è) ╪ذ┘ê╪▒╪│ ,connOK"]]

i send data with HTTP GET request like below

    var myJsonString = JSON.stringify(arr);

    page.open('http://localhost/bptest/danger/get.php?data='+myJsonString,function(status){
            console.log("Page opened");
            if (status !== 'success') {
                console.log('FAIL');
            } else {
                console.log("REPLY FROM SERVER:");
                console.log(page.content);
            }});

end my simple php file is below code :

<li><?php echo $_GET["data"]; ?></li>

and php get's this :

[["?????","67126881188552864","Empty,Empty,Empty,Em
pty,8644,-360,-4,8691,-3.48,-313,1015,4.334 M,1392/12/28,12:30:08,3.99 M,10 B,10
%,530,16.4,16.38,????,7,3130,8644,1,50,5000,

why it's crash when recive from php and how i can fix this

  • 写回答

4条回答 默认 最新

  • dongming5444 2014-03-23 00:23
    关注

    Note the <meta charset="utf-8" /> line (and the file itself should be in UTF-8 which should be the default for any decent text editor) and also the use of encodeURIComponent which is when you want to encode something to fit into the query string (since unlike encodeURI, it also encodes characters like & and =).

    HTML:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8" />
    <script>
    var arr = [["╪▒┘à┘╛┘╪د","67126881188552864","Empty,Empty,Empty,Empty,8644,-360,-4,8691,-3\
    .48,-313,1015,4.334 M,1392/12/28,12:30:08,3.99 M,10 B,10%,530,16.4,16.38,┘à╪ش╪د╪\
    ▓,7,3130,8644,1,50,5000,&nbsp;,&nbsp;,&nbsp;,8644,11553,359,307,8645,1,1,8655,11\
    030,2,┌»╪▒┘ê┘ç ┘à┘╛┘╪د (╪│┘ç╪د┘à┘è ╪╣╪د┘à) (╪▒┘à┘╛┘╪د),╪ذ╪د╪▓╪د╪▒ ╪د┘ê┘ (╪ز╪د\
    ╪ذ┘┘ê┘è ╪د╪╡┘┘è) ╪ذ┘ê╪▒╪│ ,connOK"]];
    var myJsonString = encodeURIComponent(JSON.stringify(arr));
    
    page.open('http://localhost/bptest/danger/get.php?data='+myJsonString,function(status){
        console.log("Page opened");
        if (status !== 'success') {
            console.log('FAIL');
        } else {
            console.log("REPLY FROM SERVER:");
            console.log(page.content);
        }
    });
    </script></head><body></body></html>
    

    PHP:

    Note the security risk comment (you could also avoid the risk by using "text/plain" as the content-type but then it won't get rendered as HTML if you need that).

    <?php
    header('Content-type: text/html;charset=utf-8');
    echo $_GET['data']; // You better fix this after testing, as it invites XSS scripting attacks!
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘