How to pass a JSON array as a parameter in URL

前端 未结 9 1165
一整个雨季
一整个雨季 2020-11-28 10:35

I have an requirement to pass a some values from mobile to server in a web service call and so I am planning to pass all the values in JSON format like the below

<         


        
相关标签:
9条回答
  • 2020-11-28 11:02
    let qs = event.queryStringParameters;
    const query = Object.keys(qs).map(key => key + '=' + qs[key]).join('&');
    
    0 讨论(0)
  • 2020-11-28 11:07

    Send Json data string to a web address and get a result with method post

    in C#

    public string SendJsonToUrl(string Url, string StrJsonData)
    {
        if (Url == "" || StrJsonData == "") return "";
        try
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
            request.Method = "POST";
            request.ContentType = "application/json";
            request.ContentLength = StrJsonData.Length;
            using (var streamWriter = new StreamWriter(request.GetRequestStream()))
            {
                streamWriter.Write(StrJsonData);
                streamWriter.Close();
                var httpResponse = (HttpWebResponse)request.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var result = streamReader.ReadToEnd();
                    return result;
                }
            }
        }
        catch (Exception exp)
        {
            throw new Exception("SendJsonToUrl", exp);
        }
    }
    

    in PHP

    <?php
    
    $input = file_get_contents('php://input');
    $json = json_decode($input ,true);
    
    ?>
    
    0 讨论(0)
  • 2020-11-28 11:11

    & is a keyword for the next parameter like this ur?param1=1&param2=2

    so effectively you send a second param named R". You should urlencode your string. Isn't POST an option?

    0 讨论(0)
提交回复
热议问题