Why is wget POST giving 400 Bad Request? - json

I am trying to use wget to POST a .json file to a site using the REST api. Specifically I am trying to create an issue in JIRA from my command line. I am aware that the easiest way to do this is using cURL; however, Solaris' native compiler has an issue with cURL versions before 7.49.0, so I can't connect via https which is a requirement, and I can't update cURL as I'm working on a company machine.
Every time I try to use wget to POST I get an ERROR: 400 Bad Request. It occurs to me that usually this is a problem with the json I'm trying to send but I can't for the life of me figure out what is wrong.
OS: Solaris 10
Version: wget 1.9.1
Command:
wget --post-file=data.json --http-user=[userID] --http-passwd=[userPass] --header="Content-Type: application/json" -i "uri.txt"
data.json:
{
"fields": {
"project":
{
"id": "10200"
},
"summary": "Creating issue remotely.",
"description": "Creating of an issue using project keys and issue type names using the REST API",
"issuetype": {
"name": "Story"
},
"customfield_11600": {
"id": "11303"
}
}
}
UPDATE:
I think my header is not correct when I send out my http POST. In my wget command above I set the Content-Type to application/json; however, looking at the debug information there is two Content-Type spaces in my header.
Content-Type: application/x-www-form-urlencoded
Content-Length: 175
Content-Type: application/json
Could it be that I'm setting my Content-Type incorrectly and the POST is being sent with the wrong encoding?
UPDATE 2
I think I've ruled out the above update as an issue, as removing the application/json content-type gives a 415 Unsupported Media Type error, implying that adding it makes the POST send the correct media type.
I've gotten a curl command to work properly on my windows machine and it connects via http1.1 automatically while wget connects via http1.0, I believe that when connecting via http1.0 the data being sent is appended on the end of the URI. Could this be why the server believes the json to be incorrect?

Related

How to get an authorization token from JuPyter hub using its REST APIs?

I want to start a notebook server as described here. I learnt that I need to get an auth token from this and so wanted to get the same, I have to use the api as described here. It always states "Method not allowed, 405". I am unable to figure out what is the right way to do this.
I tried the following post requests:
http://MY_JHUB_ON_K8S_SERVER.com/authorizations/token
with the body of JSON/Application:
{
"username": "aviral",
"password": "aviral",
}
The headers are:
[{"key":"Content-Type","name":"Content-Type","value":"application/json","description":"","type":"text"}]
In Postman, I had tried basic auth as well as no auth. In the basic auth, I pasted the username and password, while when there was no auth, I put the same in the json body
I expect to get the token so that I can start a server. Right now, regardless of the permutation and combination, I am getting 405.
This seems to be possible using the oath api endpoint but I wasn't successful.
Instead I run this command on the jupyterhub server to generate a token
jupyterhub token myusername
and then calls should work properly using the rest api:
curl --insecure 'https://myjupyterhubserver:8443/hub/api/users' \
-H 'Authorization: Token mygeneratedtoken'

How to do a website preview using a subdomain?

I'm trying to make a website preview with subdomain
e.g.
I've https://www.sub.example.com and CNAME to https://www.sub2.example2.com
When I do a PING command sub2.example2.com. response me, but I a navigator don't open the sub2.example2.com.
Both Domain are using a different Wildcard and I do not want to use a .htaccess
what options I have?
Don't get confused/mix things, PING behaves differently than HTTP that's why when you ping you may always get a response since you are doing the requests to the same web server or load balancer.
Regarding the HTTP request, what could be missing is a server block/virtual host to handle your request for your defined HOST: sub2.example2.com.
Once you have your vhosts's defined you could test using curl with something like this:
curl -I -H 'Host: sub.example.com' your-web-server.tld
Check the returned headers (option -I) that could give you a hint.

Issue adding attachments to documents in CouchDB

I'm having problems adding attachments in CouchDB. First off, when I ran the test suite in Futon I got two errors - one in attachments, and another in replication. The error specific to attachments isn't particularly helpful -
name
attachments
status
error
duration
6112
details
0
Exception raised: {}
Some internet commentary says that a few errors in the test suite is perfectly normal, so I moved on. However, attachments are definitely not working properly, either via Futon or Curl. In Futon, the file will generally attach, but only after I click cancel on the upload - i.e. it hangs on the upload progress bar indefinitely until I click cancel. I'm accessing futon on a remote machine via ssh -L5984:127.0.0.1:5984 root#myServer and then pointing Firefox at localhost:5984/_utils/. I don't know if that could be making a difference.
When I try to upload via Curl, using the command
curl -vX PUT http://127.0.0.1:5984/albums/6e1295ed6c29495e54cc05947f18c8af/ artwork.jpg?rev=9--43332bfae07884c683b50ffd4b8ee18c --data-binary #artwork.jpg -H "Content-Type: image/jpg"
I get:
Host: 127.0.0.1:5984
Accept: /
Content-Type: image/jpg
Content-Length: 11205
Expect: 100-continue
< HTTP/1.1 100 Continue
< HTTP/1.1 400 Bad Request
* HTTP error before end of send, stop sending
{"error":"bad_request","reason":"invalid UTF-8 JSON"}
The log file shows:
[debug] [<0.103.0>] 'PUT' /albums/6e1295ed6c29495e54cc05947f18c8af/ {1,1}
Headers: [{'Accept',"*/*"},
{'Content-Length',"11205"},
{'Content-Type',"image/jpg"},
{"Expect","100-continue"},
{'Host',"127.0.0.1:5984"},
{'User-Agent',"curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3"}]
[debug] [<0.103.0>] OAuth Params: []
[error] [<0.103.0>] attempted upload of invalid JSON (set log_level to debug to log it)
Followed by a huge block -
[debug] [<0.103.0>] Invalid JSON:
<<255,216,255,224,0,16,74,70,73,70,0,1,1,0,0,1,0,1,0,0,255,219,0,132, ... , etc
The final two lines in the log that are relevant to the attempted upload are
[info] [<0.103.0>] 127.0.0.1 - - 'PUT' /albums/6e1295ed6c29495e54cc05947f18c8af/ 400
[debug] [<0.103.0>] httpd 400 error response: {"error":"bad_request","reason":"invalid UTF-8 JSON"}
Does anyone have any idea what is going on here? I tried wrapping the string in the curl request around ' ' in case bash was eating the quotes, it made no difference.
There is a spurious space in your curl command after the slash between the doc id and the attachement:
...f18c8af/ artwork.jpg?...
^
Does it work when you remove it?
There were two problems. The first was the spurious space that Simon pointed out - tyvm. The other problem was where the rev-x details are placed. I was using the format in the book http://guide.couchdb.org/editions/1/en/api.html.
Original command:
curl -vX PUT http://127.0.0.1:5984/albums/6e1295ed6c29495e54cc05947f18c8af/ artwork.jpg?rev=9--43332bfae07884c683b50ffd4b8ee18c --data-binary #artwork.jpg -H "Content-Type: image/jpg"
Working command (space removed & rev placed in the correct order):
curl -vX PUT http://127.0.0.1:5984/albums/6e1295ed6c29495e54cc05947f18c8af/attachment?rev=9-43332bfae07884c683b50ffd4b8ee18c --data-binary #artwork.jpg -H "Content-Type: image/jpg"

curl get json returns 404

I'm running a tomcat server with a REST service on localhost.
This url typed in the browser gives me a json response: http://localhost:8080/a/rest/dataset/list
But when I use curl: curl http://localhost:8080/a/rest/dataset/list the response is HTML code with a 404 error from the server.
What am I missing in the curl command?
Tomcat may be waiting for a specially formatted HTTP request from the user. As you are expecting a response in json, you should probably forward the following argument to curl :
-H 'Content-Type: application/json'
Also, you may always specify to whatever HTTP server the response you are expecting him to return. A lot of back-end application based on HTTP are issuing a response given the HTTP request.

Drupal JSON Server and Services Module only returns Invalid Method

I have been trying to get a stock Drupal site up and running with JSON Server module and Services. After install I added the two modules and enabled them. When I use Curl from the command line to call system.connect or anything I only get Invalid Method.
curl --data method=system.connect http://localhost/services/json
This is what I am getting back.
{ "#error": true, "#data": "Invalid method " }
I remember having the same problem myself a while back. Your problem at the moment is that your post data does not have quotes.
curl --data 'method="system.connect"' http://localhost/services/json
If you have a look at this: http://drupal.org/node/305799 it should give you loads more info to get you going with services and the json server.