i have a service .svc hosted on a machine whit windows server 2019 on IIS 10,
im tryng to send a POST request whit postman sending a json whit the following headers:
Postman-Token: calculated when request is sent>
Content-Lenght: calculated when request is sent
Host: calculated when request is sent
Accept: * / *
Content-Type: application/json
and this in the body:
{
"orderNumber": "12345",
"idTransaction":"1",
"authorization":"auth",
"amount":"14.95",
"paymentDate":"2020-01-01",
"currency":"euro",
"resultCode": "ok"
}
the service responds correctly and read the json but the status is "406 Not Accettable"
as you can see i have placed the Accept header whit value "* / *" that mean accept every kind of content-type and that is the response that i get
response headers:
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/10.0
X-Powered-By: ASP.NET
Date: Mon, 04 Jan 2021 09:54:27 GMT
Content-Length: 69
response body
"Not found any payment whit numeroOrdine=12345."
the server/service read the json and respond corretly couse the number of order 12345 was an example and dosent exist,
but whit status code 406 not accetable,
i tryed also to add the header Accept-Charset: UTF-8 in the request but the situation dosent change,
i checked on iis on the server and after select on the mime type list i can that application/json is in the list,
Mime type IIS
maybe i have to enable it somewhere else? Specify the mime type in the web.config file?
or it could be something else?
thanks in advance
Following the advice from this question, and the API documentation (e.g., Blob service REST API), I have an x-ms-version specified in the header. My code works against Azurite, and is authenticated by Azure, but returns a
HTTP/1.1 400 The value for one of the HTTP headers is not in the correct format.
The xml body has more details:
<Error>
<Code>InvalidHeaderValue</Code>
<Message>The value for one of the HTTP headers is not in the correct format.
RequestId:d39d2cad-301e-009e-1546-3940de000000
Time:2018-08-21T11:58:14.2369850Z</Message>
<HeaderName>x-ms-version</HeaderName>
<HeaderValue>2017-01-19</HeaderValue>
</Error>
My guess is it is not the format, but the value. How do I find the right value, or even a list of all possible values that I can try running one at a time, or does someone know that this is a misleading error, and I need to be looking somewhere else?
While playing with this a little more a x-ms-version=2015-02-21 generates.
HTTP/1.1 400 One of the request inputs is out of range.
Here is the request:
-> GET /mike-ecu-test?restype=container&comp=list HTTP/1.1
-> Host: mikeecutest.blob.core.windows.net
-> User-Agent: libcurl/7.54.0 r-curl/3.1 httr/1.3.1
-> Accept-Encoding: gzip, deflate
-> Accept: application/json, text/xml, application/xml, */*
-> Authorization: SharedKey mikeecutest/mike-ecu-test:9j5XodD9OIslzMnzHXiU7c76EpOXFi5jeQITbHk/Y8g=
-> x-ms-date: Wed, 22 Aug 2018 01:35:06 GMT
-> x-ms-version: 2018-03-28
Here is the r code that generates it, credit for the code is answer 4 to this question
library("httr")
azureout <- function(){
url <- "http://mikeecutest.blob.core.windows.net/mike-ecu-test?restype=container&comp=list"
sak <- "dfgwhsfhsfg.....hjdkfgs=="
requestdate<-format(Sys.time(),"%a, %d %b %Y %H:%M:%S %Z", tz="GMT")
msapiversion<- "2018-03-28"
signaturestring<-paste0("GET",paste(rep("\n",12),collapse=""),
"x-ms-date:",requestdate,
"x-ms-version:",msapiversion,"\n",
"mikeecutest", "\n",
"comp:list","\n",
"restype:container")
headerstuff<-add_headers(Authorization=paste0("SharedKey mikeecutest/mike-ecu-test:",
RCurl::base64(digest::hmac(key=RCurl::base64Decode(sak, mode="raw"),
object=enc2utf8(signaturestring),
algo= "sha256", raw=TRUE))),
`x-ms-date`=requestdate,
`x-ms-version`=msapiversion)
content(GET(url,config = headerstuff, verbose() ))
}
Storage API version 2018-03-28 generates a:
<- HTTP/1.1 400 One of the request inputs is out of range.
Storage API version 2018-02-01 generates a:
<- HTTP/1.1 400 The value for one of the HTTP headers is not in the correct format.
You are right, 2017-01-19 is not a valid Storage service version, see all versions here. The documentation article Versioning for the Azure Storage services also suggests the latest API version at the top.
Recommend you to use the latest if there is no specific requirement.
Update
See three points to fix:
signaturestring<-paste0("GET",paste(rep("\n",12),collapse=""),
"x-ms-date:",requestdate,"\n", # miss "\n"
"x-ms-version:",msapiversion,"\n",
"/mikeecutest/mike-ecu-test", "\n", # should be /accountname/containername
"comp:list","\n",
"restype:container")
headerstuff<-add_headers(Authorization=paste0("SharedKey mikeecutest:", # only need accountname here
RCurl::base64(digest::hmac(key=RCurl::base64Decode(sak, mode="raw"),
object=enc2utf8(signaturestring),
algo= "sha256", raw=TRUE))),
`x-ms-date`=requestdate,
`x-ms-version`=msapiversion)
Package of REST API is always preferred, you can have a try at that provided by #Hong.
Consider using my AzureStor package which is an interface to file and blob storage on Azure. It handles authentication, including both access key and SAS, and admin details like getting the API version right.
install.packages("AzureStor")
library(AzureStor)
bl <- blob_endpoint("http://mikeecutest.blob.core.windows.net",
key="your_key")
cont <- blob_container(bl, "mike-ecu-test")
list_blobs(cont)
upload_blob(cont, "srcfile", "destblob") # blocked upload is supported for blob storage
download_blob(cont, "srcblob", "destfile")
newcontainer <- create_blob_container(bl, "newcontainer")
delete_blob_container(newcontainer)
I am trying to use R to access a web page in our organization using httr GET.
However i get a message that "Access is denied due to invalid credentials".
I can do the desired action manually.
it seems that authorization is done automatically when i use internet explorer to get to the web site but the access is blocked when trying to do the same action through R.
This is how i'm trying to do it:
(I can't supply the exact address because it's an intranet address which can be used only inside the organization the same for the proxy address)
library(httr)
r <- GET(myurl, useproxy(myproxyid, 80), verbose())
-> GET http: //myurl
-> host: xxx
-> User-Agent : libcurl...
-> Accept-Encoding: gzip, deflate
-> Proxy-Connection: Keep-Alive
-> Accept: application/json, text/xml, application/xml, *.*
<- HTTP/1.1 401 Unauthorized
<- Content-Type: text/html
<- Server: Microsoft-IIS/8.5
<- WWW-Authenticate: Negotiate
<- WWW-Authenticate: NTLM
<- X-Powered-By: ASP.NET
r
Response [myurl]
Date
Status: 401
...
<title>401 - Unauthorized: Access is denied due to invalid credentials.</title>
....
I understand that i somehow have to send my credentials with my request.
is it possible to somehow use automatic authentication?
Thanks
Rafael
OK
I finally made it.
I had to supply authentication data to my get command like this:
library(httr)
r <- GET(myurl,
useproxy(myproxyid, 80),
verbose(),
authenticate(user = "myuserid", password = "mypassword", type = "ntlm"))
I hope it helps anybody
Thanks
Rafael
I have a program that activate an chip for racing results. (Its just a piece of hardware).
I watch with Fiddler (Sniffing program) the in and outgoing traffic from my pc when I connect the chip with my computer.
The program sends the following HTTP Request:
POST http://example.com/index.php HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
Content-Length: 185
Content-Type: application/x-www-form-urlencoded
Host: example.com
Pragma: no-cache
User-Agent: SomeProgram 1.2.3
Data==%0D%0AAjlFNEEw-SOMELONGSECRETKEY-RGAw%3D%3D%0D%0A
I receive the following response:
<?xml version="1.0" encoding="utf-8"?>
<message type="3" result="1" txid="someid" activationdate="" availablecredits="732" firstname="John" lastname="Doe" email="JohnDoe#outlook.com" phonenumber="00123445" notification_email="1" notification_text="1"/>
Is it possible to edit the response so that when the programs check for the availablecredits variable, he get the value 9999 instead of 732.
Im working on a Windows 8 laptop.
Definitely - Fiddler allows you to modify requests and responses by adding rules to FiddlerScript. Citing Fiddler documentation:
To make custom changes to web requests and responses, use
FiddlerScript to add rules to Fiddler's OnBeforeRequest or
OnBeforeResponse function. Which function is appropriate depends on
the objects your code uses: OnBeforeRequest is called before each
request, and OnBeforeResponse is called before each response.
So, all you have to do is to add to OnBeforeResponse the logic for replacing the availablecredits attribute value with any value you desire.
Let`s assume that program 'xyz' use pretty simple authentication via HTTP/1.1 GET method. What i want to do is modify response header, exactly from "Content: 1; Bad User Name or Password" to "Content: 0; Pass".
To be more specific:
0) I'm using win 7 x86, program 'xyz' was written in VB. Fiddler is not capturing packets, btw don't know why ;-( => i wanted to use AutoResponder. Wireshark captures nicely ;-)
1) I run 'xyz' and fill credentials: User Name = 'fake_foo' and Password = 'fake_bar' than press login
2) In wireshark i see HTTP request packet to 111.222.223.224:80:
GET /result?u=fake_foo&p=fake_bar HTTP/1.1
User-Agent: CheckL
TimeStamp: 1234567890
Host: 111.222.223.224:80
3) Next packet is response from that server:
HTTP/1.1 200 OK
Date: 05:00:00 AM
Content-Type: text/html
Content: 1;Bad User Name or Password
Now when i put reliable credentialas than response is:
HTTP/1.1 200 OK
Date: 05:00:00 AM
Content-Type: text/html
Content: Content: 0; Pass
and program starts.
How to, what software can use to modify on the fly this response to be 'pass' after sending request with fake data?
Thanks