Bitcoind JSON RPC auth not working - json

I have runing bitcoind on ubuntu. bitcoin-cli works fine. I can not get working json rpc protocol
bitcoin.conf file:
testnet=0
rpcuser="bitcoinrpc"
rpcpassword="xxxxx"
rpcport=8332
rpcallowip="*"
server=1
http post request with url='http://bitcoinrpc:xxxxx#127.0.0.1:8332/' fails with 401 error.
request headers:
Accept:*/*
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8,ru;q=0.6,de;q=0.4,sr;q=0.2
Authorization:Basic Yml0Y29pbnJwYzp4eHh4eA==
Cache-Control:no-cache
Connection:keep-alive
Content-Length:53
Content-Type:text/plain
DNT:1
Host:127.0.0.1:8332
Origin:chrome-extension://fhjcajmcbmldlhcimfajhfbgofnpcjmb
Pragma:no-cache
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/51.0.2704.79 Chrome/51.0.2704.79 Safari/537.36
request post payload:
{jsonrpc: "2.0", method: "getinfo", params: []}
What is correct way for bitcoind json rpc autentification?

For future googlers: a possible problem is that the password should not contain the pound sign (#) as this is treated as a comment!

Related

Keep getting HTTP code 422, not sure whats wrong with the json payload

I am making a python module that interacts with Carousell using the requests module. Now I am trying to send a post request with a JSON payload, but I keep getting HTTP error code 422(UNPROCESSABLE ENTITY). I don't know what's wrong with my JSON payload, python dict(before it's converted to JSON) or perhaps I am missing something in my request headers.
I tried taking the raw json string(from the POST request that I captured using Chrome dev tools) converting it dict and copy that dict(printed out) and try to use it in the program. It didn't work.
login_session = requests.session()
login_session.headers.update({"DNT":"1", "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Safari/537.36", "Origin":"https://sg.carousell.com"})
login_payload = {'requests': {'g0': {'resource': 'sso', 'operation': 'create', 'params': {'loginToken': cookies["login-token"]}, 'body': {}}}, 'context': {'_csrf': cookies["_csrf"]}}
login_cookies = {"__cfduid": cookies["__cfduid"], "_csrf": cookies["_csrf"], "gtkprId": cookies["gtkprId"], "login-token": cookies["login-token"], "redirect":"redirect"}
login_headers = {'accept':'*/*','accept-encoding':'gzip, deflate, br','accept-language':'en-GB,en;q=0.9,zh-CN;q=0.8,zh;q=0.7,en-US;q=0.6', 'x-requested-with': 'XMLHttpRequest', 'content-type': 'application/json'}
login_data = login_session.post(query_url, cookies=login_cookies, data=json.dumps(login_payload), headers=login_header)
Heres the output from debugging logger
DEBUG:urllib3.connectionpool:https://sg.carousell.com:443 "POST /ui/iso?_csrf=TNZTMZpBdQYgRFFouCF4ELVB HTTP/1.1" 422 0
Edit:
Heres the JSON payload which was sent to the server. I am trying to replicate it.
{"requests":{"g0":{"resource":"sso","operation":"create","params":{"loginToken":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1NTg1MDQyMjQsImlzcyI6ImxvZ2luLmNhcm91c2VsbC5jb20iLCJzc29pZCI6IkRacG1rd1l1SXAxdDF5U3A2M1RXWExPUTJnWmRFRzBOSHd3d0ZGSm9PSkFvVFFOdGFyNWt0MDMzNm5EVHRudHoiLCJ1c2VyaWQiOiIxNDczMjI3NCJ9.x7YxdLLk1ID6_jWy4trtLzbrPnZZ0eI7g_cQN1BilF8"},"body":{}}},"context":{"_csrf":"hPPhgajp-1GMLSbgjZBNBD7z2EGPVGCuA_mU"}}
Note that login token and _csrf are data from the cookies.

Angular won't post data to API

I got a problem which I dont understand.
I try to post data to my API in a form using the following code
formSubmit() {
const req =this.http.post('http://[ip]/api/login', {
id: '7',
username: 'PostTest',
password: 'studp123lan',
matrikelnr: 'winf303666',
email: 'winf303666#example.de',
email_verified: '1'
})
.subscribe(
res => {
console.log(res);
},
err => {
console.log("Error occured");
}
When I inspect it in the Chrome Developter tools, this is what I get:
Failed to load http://[ip]/api/login: Response for preflight has
invalid HTTP status code 404
register.component.ts:42 Error occured
And this is what I get in the network tab:
General:
Request URL:http://[ip]/api/login
Request Method:OPTIONS
Status Code:404 Not Found
Remote Address:[ip]:80
Referrer Policy:no-referrer-when-downgrade
Response Header:
Access-Control-Allow-Headers:Content-Type
Access-Control-Allow-Methods:GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Origin:*
Content-Length:0
Date:Thu, 21 Dec 2017 09:00:35 GMT
Server:Kestrel
X-Powered-By:ASP.NET
Request Header:
Accept:*/*
Accept-Encoding:gzip, deflate
Accept-Language:de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7
Access-Control-Request-Headers:content-type
Access-Control-Request-Method:POST
Connection:keep-alive
Host:[ip]
Origin:http://localhost:4200
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36
Somehow, this doesn't work. But when I Post the same data via Postman Post Request to the same URL, it works like a charm.
Can anyone explain and help?
Thanks.
404 is a page not found error : this means your endpoint isn't available at this address.
Sure, you make a postman call and it works : but did you create your postman call by hand, or used the interceptor to make it ? (The interceptor is a Chomr plugin that allows you to register all calls made by Chrome, into postman).
There must be something you have forgotten. Could you post your postman call, and if you can, try with the interceptor ?

Resty-GWT MeduaType

How can I change media-type in request
#Path("/admin")
public interface LoginService extends RestService {
LoginService INSTANCE = GWT.create(LoginService.class);
#Path("/login")
#POST
#Produces({ MediaType.APPLICATION_JSON })
#Consumes({ MediaType.APPLICATION_JSON })
void login(MethodCallback<List<LoginBean>> callback);
}
But in network I see
Request URL:https://localhost:8443/services/v2/admin/login
Request Method:OPTIONS
Status Code:200
Remote Address:127.0.0.1:8443
Response Headers
allow:POST, OPTIONS
content-length:13
**content-type:text/plain**
date:Mon, 06 Feb 2017 11:15:46 GMT
server:WildFly/10
status:200
x-powered-by:Undertow/1
Request Headers
:authority:localhost:8443
:method:OPTIONS
:path:/services/v2/admin/login
:scheme:https
accept:*/*
accept-encoding:gzip, deflate, lzma, sdch, br
accept-language:ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4
access-control-request-headers:authorization, content-type, x-http-method-override
access-control-request-method:POST
origin:http://127.0.0.1:8888
referer:http://127.0.0.1:8888/AdminConsole.html
user-agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36 OPR/42.0.2393.517
In RestyGwt documentation says, but seems it don't work(
Configuring the Accept and Content-Type and HTTP Headers
RestyGWT rest calls will automatically set the Accept and Content-Type and HTTP Headers to match the type of data being sent and the type of data expected by the callback. You can override these default values by adding JAX-RS’ #Produces and #Consumes annotations to the method declaration.
https://resty-gwt.github.io/documentation/restygwt-user-guide.html

POST error when sending JSON data in Grinder

The requirement is to make a POST request to a particular URL with a given JSON payload. The URL will only respond if the payload is correct and the request is via POST.
This is my code:
request1 = HTTPRequest()
control = HTTPPluginControl.getConnectionDefaults()
httpUtilities = HTTPPluginControl.getHTTPUtilities()
control.setProxyServer("proxy.example.com", 1234)
payload = JSONObject({
"uaaURL": "https://com-example.something.com",
"sampleID": "admin",
"sampleSecret": "password",
"sampleID2": "example-sample-el",
"sampleSecret2": "ssenjsoemal/+11=",
"username": "test",
"someAttributes": {
"Groups": [
"example_com-abc"
],
"attribute": [
"value1"
]
}
})
payload = str(payload)
url = "https://example-something.com:6443/getvalues"
headers = [
NVPair('Content-Type', 'application/json'),
NVPair('Charset', 'UTF-8'),]
class TestRunner:
def __call__(self):
result = request1.POST(url, payload, headers)
print payload, headers
Now the issue with this is that my POST request gives me a 403 forbidden. However, when I use the same payload and send the request using DHC, it gives me a 200. So I'm sure of the payload and the link I'm connecting to. The proxy also I've tested in another script and works fine. Besides, if the proxy didn't work, I wouldn't get a 403 either.
Lastly, I'm parsing it as a string because POST requires the second argument to be string that it will internally convert into byte[].
I'm really not able to understand what's happening so any insight would be immensely helpful. Thanks in advance
EDIT: Fiddler's catch of DHC's Request
POST https://example-something.com:6443/getvalues HTTP/1.1
Host: example-something.com:6444
Connection: keep-alive
Content-Length: 688
Origin: chrome-extension://aejoelaoggembcahagimdiliamlcdmfm
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36
Content-Type: application/json
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.8
{
"uaaURL": "https://com-example.something.com",
"sampleID": "admin",
"sampleSecret": "password",
"sampleID2": "example-sample-el",
"sampleSecret2": "ssenjsoemal/+11=",
"username": "test",
"someAttributes": {
"Groups": [
"example_com-abc"
],
"attribute": [
"value1"
]
}
}
I even edited my Grinder request headers to so
headers = (
NVPair('Content-Type', 'application/json'),
NVPair('Charset','UTF-8'),
NVPair('Accept', '*/*'),
NVPair('Accept-Encoding', 'gzip, deflate, br'),
NVPair('Accept-Language', 'en-US,en;q=0.8'),
NVPair('Connection', 'keep-alive'),
)
Best guess? You are likely missing a header with some credential information to pass a proxy/firewall/access gate to the application. Your REST Client, DHC, likely is passing this additional data but grinder is not. Grab a proxy (Fiddler, Charles, etc...) and check out the handshake from DHC to your destination and then match that with Grinder. My guess is you will find the delta.
The issue was that Grinder was not able to access the port. It had nothing to do with the JSON. The URL, which runs on port 6443 was the problem and Grinder couldn't access that (don't know why). I changed my URL itself to run on the default port 8080 and instantly my script worked. Thanks for the help!

jsonp not working on my webserver

I'm new to JSONP and I'm trying to access a cross domain file hosted on my webserver.
UPDATE: I found another solution to fix my issue: I used CORS for JQUERY of http://www.html5rocks.com/en/tutorials/cors/
Here is my js file:
var url = "myip:port/pgif.jsonp?callback=?"
var url2 = "http://puppygifs.tumblr.com/api/read/json?callback=?";
$.getJSON(url2, {
tags: "jquery",
tagmode: "any",
format: "json"
}, function (data) {
console.log("d= ", data);
});
}
);
When I try with url2, it works well but when I try with url to access my file on my webserver it doesn't.
Here is what I can see in the Network tab of Chrome Dev tools with url2 which works:
Request URL:http://puppygifs.tumblr.com/api/read/json?callback=jQuery19107969533477444202_1386114768597&tags=jquery&tagmode=any&format=json&_=1386114768598
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en,fr-FR;q=0.8,fr;q=0.6
Cookie:__utma=189990958.626465526.1385955515.1385955515.1385955515.1; __utmc=189990958; __utmz=189990958.1385955515.1.1.utmcsr=sarajchipps.com|utmccn=(referral)|utmcmd=referral|utmcct=/2011/01/using-jquery-ajax-calls-in-a-chrome-plugin.html
Host:puppygifs.tumblr.com
Proxy-Authorization:Negotiate TlRMTVNTUAADAAAAGAAYAIQAAABiAWIBnAAAAAwADABYAAAAEAAQAGQAAAAQABAAdAAAABAAEAD+AQAAFYKI4gYBsR0AAAAPwICK4LzPlRZWoe1WgJ+erkYATwBYAFQARQBMAGIAYQBzAHQAaQBkAGUAZgBIAFEAMAAyADcANAAzADUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA+t3F+qb2rUYkHj2KQg3XtAEBAAAAAAAAanrqyYLwzgG/iL4+KqlreQAAAAACAAwARgBPAFgAVABFAEwAAQAQAFMAWQBEAFQATQBHADAAMQAEACIAZQBuAHQALgBmAG8AeAB0AGUAbAAuAGMAbwBtAC4AYQB1AAMANABTAFkARABUAE0ARwAwADEALgBlAG4AdAAuAGYAbwB4AHQAZQBsAC4AYwBvAG0ALgBhAHUABQAiAGUAbgB0AC4AZgBvAHgAdABlAGwALgBjAG8AbQAuAGEAdQAHAAgAanrqyYLwzgEGAAQAAgAAAAgAMAAwAAAAAAAAAAAAAAAAIAAA+jYk8RidWxnk5XJtyRLc7j6jPZX/e7BWswB5GZeS2JYKABAAAAAAAAAAAAAAAAAAAAAAAAkAIgBIAFQAVABQAC8AMQAwAC4AMgAwAC4AMQA2AC4AMQAwADAAAAAAAAAAAAAAAAAA2S3kxHzp0FstuiERqIRwqQ==
Proxy-Connection:keep-alive
Referer:http://ip:port/MyApp/index.html
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36
Query String Parametersview sourceview URL encoded
callback:jQuery19107969533477444202_1386114768597
tags:jquery
tagmode:any
format:json
_:1386114768598
Response Headersview source
Cache-Control:max-age=900
Connection:Keep-Alive
Content-Type:text/javascript
Date:Tue, 03 Dec 2013 23:52:57 GMT
Last-Modified:Sun, 03 Feb 2013 12:02:52 GMT
P3P:CP="ALL ADM DEV PSAi COM OUR OTRo STP IND ONL"
Proxy-Connection:Keep-Alive
Transfer-Encoding:chunked
Vary:X-UA-Device
Via:1.1 SYDTMG01
X-Cache-Metadata:
X-Robots-Tag:noindex
X-UA-Device:desktop
Here is what I can see in the Network tab of Chrome Dev tools with url which doesnt work:
Request URL:http://ip:port/pgif.jsonp?callback=jQuery1910627754604909569_1386116200762&tags=jquery&tagmode=any&format=json&_=1386116200763
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en,fr-FR;q=0.8,fr;q=0.6
Connection:keep-alive
Host:ip:port
Referer:http://ip:port/MyApp/index.html
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36
Query String Parametersview sourceview URL encoded
callback:jQuery1910627754604909569_1386116200762
tags:jquery
tagmode:any
format:json
_:1386116200763
Response Headersview source
Accept-Ranges:bytes
Access-Control-Allow-Origin:*
Content-Length:6616
Content-Type:application/javascript
Date:Thu, 01 Jan 1970 02:02:33 GMT
ETag:"68647623"
Last-Modified:Thu, 01 Jan 1970 01:23:16 GMT
Server:lighttpd/1.4.30
So as you can see, in the last one, I added Access-Control-Allow-Origin:* in the config of my lighttpd webserver, which doesnt improve the situation.
so I dont really understand, I receive an Ok answer from the webserver but my success function is never called.
Here is the JSONP file I'm trying to access on my webserver:
var tumblr_api_read = {"tumblelog":{"title":"puppy gifs"},"posts-start":0,"posts-total":"18"}
So, I didn't managed to make the JSONP work with my web server but I found a different way to solve my problem:
I followed the "CORS from JQuery" from html5rocks.com/en/tutorials/cors
And I'm now able to read my file sitting on my webserver.
It seems like if I want to edit my file, I would need to configure my web server to be able to handle the preflight request. As explained in x3dom.readthedocs.org/en/latest/notes/cors.html