相关疑难解决方法(0)

如何将请求有效负载发送到Java中的REST API?

我想从以下内容中检索JSON数据:https: //git.eclipse.org/r/#/c/11376/

请求网址: https://git.eclipse.org/r/gerrit/rpc/ChangeDetailService

请求方法: POST

请求标题:

Accept:application/json

Content-Type:application/json; charset=UTF-8
Run Code Online (Sandbox Code Playgroud)

请求有效负载:

{"jsonrpc":"2.0","method":"changeDetail","params":[{"id":11376}],"id":1}
Run Code Online (Sandbox Code Playgroud)

我已经尝试过这个答案,但我得到了400 BAD REQUEST.

任何人都可以帮我解决这个问题吗?

谢谢.

java rest httpurlconnection http-status-code-400

26
推荐指数
1
解决办法
11万
查看次数

Android:如何创建HMAC MD5字符串?

我正在尝试创建一个Android MD5哈希字符串,以等于下面的C#代码:

private string CalculateHMACMd5(string message, string key)
{
     System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
     byte[] keyByte = encoding.GetBytes(key);
     HMACMD5 hmacmd5 = new HMACMD5(keyByte);
     byte[] messageBytes = encoding.GetBytes(message);
     byte[] hashmessage = hmacmd5.ComputeHash(messageBytes);
     string HMACMd5Value = ByteToString(hashmessage);
     return HMACMd5Value;
}

private static string ByteToString(byte[] buff)
{
    string sbinary = "";
    for (int i = 0; i < buff.Length; i++)
    {
        sbinary += buff[i].ToString("X2"); 
    }
    return (sbinary);
}
Run Code Online (Sandbox Code Playgroud)


我目前使用的Android代码[ 不生成相同的C#代码 ]:

        public static String sStringToHMACMD5(String sData, String sKey) 
        {
            SecretKeySpec key;
            byte[] bytes; …
Run Code Online (Sandbox Code Playgroud)

java hash android md5 hmac

5
推荐指数
2
解决办法
1万
查看次数

Java:将原始数据添加到有效负载Httpost请求中

我打算在Payload中发送一个带有大字符串的简单http post请求.

到目前为止,我有以下内容.

    DefaultHttpClient httpclient = new DefaultHttpClient();


    HttpPost httppost = new HttpPost("address location");

    String cred = "un:pw";

    byte[] authEncBytes = Base64.encodeBase64(cred.getBytes());
    String authStringEnc = new String(authEncBytes);



    httppost.setHeader("Authorization","Basic " + authStringEnc);
Run Code Online (Sandbox Code Playgroud)

但是,我不知道如何将简单的RAW字符串附加到有效负载中.我能找到的唯一例子是实体中的名称值对,但这不是我想要的.

任何帮助?

java http-post payload

5
推荐指数
1
解决办法
3万
查看次数