Invalid nonce kraken - kraken.com

I am getting {"error":["EAPI:Invalid nonce"]} while calling https://api.kraken.com/0/private/AddOrder end point.
passing following params in form of json:
JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("pair", "XXBT");
jsonObject.accumulate("type ", "sell");
jsonObject.accumulate("ordertype ", "market");
jsonObject.accumulate("price", "2");
jsonObject.accumulate("volume", "1");
Setting API-Key and API-Sign as well.
nonce = String.valueOf(System.nanoTime());
Generating nonce using above logic. Any idea where I am going wrong?

Try increase option Nonce Window to 5000-10000. You can find this option here.

Related

How to set url encoded form entity and add params to form entity in rest assured?

The below sample code is in http client , But I want to write the same in Rest Assured. I know we can use the http lib in rest assured as well, But I want to have in Rest assured
HttpPost pst = new HttpPost(baseUrl, "j_spring_security_check"))
pst.setHeader("Content-Type", "application/x-www-form-urlencoded")
ArrayList<NameValuePair> postParam = new ArrayList<NameValuePair>()
postParam .add(new BasicNameValuePair("j_username",username))
postParam .add(new BasicNameValuePair("j_password",password))
UrlEncodedFormEntity formEntity23 = new UrlEncodedFormEntity(postParam)
pst.setEntity(formEntity23 )
HttpResponse response = httpclient.execute(pst);
For Rest Assured you can use below code snippet.
Response response = RestAssured
.given()
.header("Content-Type", "application/x-www-form-urlencoded")
.formParam("j_username", "uName")
.formParam("j_password", "pwd")
.request()
.post(url);
As, your application is using form url-encoded content type you can set the Header type to this as mentioned above.
Hope, this helps you.
#Test
public void postRequestWithPayload_asFormData() {
given().contentType(ContentType.URLENC.withCharset("UTF-8")).formParam("foo1", "bar1").formParam("foo2", "bar2").log().all()
.post("https://postman-echo.com/post").then().log().all().statusCode(200)
.body("form.foo1", equalTo("bar1"));
}
Add content type of URLENC with charaset as UTF-8. It works will latest rest assured.

How to make a GET Request using okhttp

I am new to Android Development and I would like to know how to perform a GET request using okhttp. I have referred http://square.github.io/okhttp/, but they only have examples of POST request. I have tried this -
okHttpClientLogin = new OkHttpClient();
requestBodyLogin = new FormBody.Builder()
.addEncoded("name", name_input) // params
.addEncoded("keys", keys_input) //params
.build();
requestLogin = new Request.Builder()
.addHeader("Authorization", token_type + " " +access_token)
.url(LOGIN_URL)
.get()
.build();
and got an Error :
{"status":{"status":206,"msg":"No record found"},"user":null}
I know why this error is coming, because the params have not been entered. I also tried passing requestBodyLogin inside .get() but it's not allowing.
Since OkHTTP 2.4, there's the function addQueryParameter. You can either use a HttpUrl, a String or a java.net.URL as url.
Basically, just create a new HttpUrl.Builder() and use the function addQueryParameter.
Example taken from the javadocs:
HttpUrl url = new HttpUrl.Builder()
.scheme("https")
.host("www.google.com")
.addPathSegment("search")
.addQueryParameter("q", "polar bears")
.build();
http://square.github.io/okhttp/3.x/okhttp/okhttp3/HttpUrl.html
http://square.github.io/okhttp/2.x/okhttp/com/squareup/okhttp/HttpUrl.Builder.html#addQueryParameter-java.lang.String-java.lang.String-

Sending String[] Array over J2ME Socket Connection using ObjectOuputStream

I am trying to send a String[] array in j2me using ObjectOUputStream, but i keep getting this error,
java.lang.IllegalArgumentException: Not an HTTP URL
Here is my code:
OutputStream os=null;
HttpConnection hc= null;
ObjectOutputStream oj=null;
//get the URL
String serverURL=entry.getUrl();
hc=(HttpConnection)Connector.open(serverURL, Connector.READ_WRITE, true);
hc=(HttpConnection)Connector.open(serverURL);
hc.setRequestMethod (HttpConnection.POST);
hc.setRequestProperty ("Content-Type", "application/x-www-form-urlencoded");
hc.setRequestProperty ("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0");
hc.setRequestProperty ("Content-Language", "en-US");
System.out.println ("Posting to the URL: " + entry.getVectorParams());
//open the output stream to send the post parameters
//os=hc.openOutputStream();
oj=(ObjectOutputStream)hc.openOutputStream();
//writing post parameters
String[] bg=entry.getVectorParams();
oj.writeObject(bg);
Please give a suggestion.
I checked my URL, it is correct and regarding Connector.open(), i pasted it twice here, not in my actual code. Is there anything else that I am doing wrong?
The System.out.println("Posting to the URL: " + entry.getVectorParams()), this only prints the post parameters, I have the serverurl passed in here:
String serverURL=entry.getUrl();
hc=(HttpConnection)Connector.open(serverURL, Connector.READ_WRITE, true);
My server URL is : http://localhost:8080/Web/gServer.jsp
The value of your serverURL variable must not be a valid URL. Try printing it out, and checking.
You have this debug statement:
System.out.println ("Posting to the URL: " + entry.getVectorParams());
but that is printing out the params, not the url. You should print out the serverURL variable.
Also, you are calling Connector.open() twice in a row. There's no need for that.
Update: I also think there could be a problem with the way you're writing the POST parameters to your connection's OutputStream. I wouldn't use an ObjectOutputStream. See something like this for an example of making J2ME POST calls. Basically, you make a String of the POST parameters, separated by &, and then use String.getBytes() to convert to a byte[] for writing to the OutputStream.

How To URLEncode Facebook Post Data in C#

I am rewriting code from http://blog.blackballsoftware.com/2010/11/03/making-a-facebook-wall-post-using-the-new-graph-api-and-c/ to create a class to post to Facebook. The code works as long as I do not URLEncode the post data. For example: If the post data is "message=Test,please ignore" then it works. If I URLEncode the same data into "message%3dTest%2cplease+ignore" then I get the error {"error":{"message":"(#100) Missing message or attachment","type":"OAuthException","code":100}}.
Should the Post data be URLEncoded? I think it should because if I post a message like this, "Test&Message", then only the word Test appears.
Relevant code is below. If postParams = HttpUtility.UrlEncode(postParams); is commented out, then the code works. If not, Facebook returns the error that the message is missing.
postParams = HttpUtility.UrlEncode(postParams);
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(postParams);
webRequest.ContentLength = bytes.Length;
System.IO.Stream os = webRequest.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
os.Close();
try
{
var webResponse = webRequest.GetResponse();
}
catch (WebException ex)
{
StreamReader errorStream = null;
errorStream = new StreamReader(ex.Response.GetResponseStream());
error = errorStream.ReadToEnd() + postParams;
}
The answer can be found on Stackoverflow at C# Escape Plus Sign (+) in POST using HttpWebRequest. Use Uri.EscapeDataString and not URLEncode. Encode the parameter value only and not the equals sign after the parameter name. Example: message=Test%2Cplease%26%20ignore works but message%3dTest%2Cplease%26%20ignore does not work because the equals after the parameter name is encoded as %3d.

Invoking REST API for making new component in JIRA

I've to make a new Component in JIRA
I found out the POST url /rest/api/2/component for making new component, but i'm unable to know what type of inputs to be given.
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost("http://localhost:8080/rest/api/2/component/");
String authorization = JiraRequestResponseUtil.conversionForAuthorization();
postRequest.setHeader("Authorization", authorization);
StringEntity input = new StringEntity("\"name\":\"Component 1\",\"description\":\"This is a TEST JIRA component\" ,\"leadUserName\":\"fred\",\"assigneeType\":\"PROJECT_LEAD\",\"isAssigneeTypeValid\":\"false\",\"project\":\"TEST\"");
input.setContentType("application/json");
postRequest.setEntity(input);
HttpResponse response = httpClient.execute(postRequest);
this is the code i'm implementing.
Output i'm getting is Failed : HTTP error code : 400
Plz help.
we can't tell you. You need to find documentation on the service you are posting to.
The above code is correct, just add the { & } to the JSON string.