I am attempting to use the Azure Rest API to update a Scheduled Job. I've successfully been able to get a list of the of the Jobs properties, so I know the authentication is working. I'm basing this on their example here:
https://msdn.microsoft.com/en-us/library/azure/dn528934.aspx
Here is what I see in Fiddler when preforming the PATCH request.
REQUEST:
PATCH https://management.azure.com/subscriptions/[[mysub]]/resourceGroups/CS-WebJobs-NorthCentralUS-scheduler/providers/Microsoft.Scheduler/jobCollections/WebJobs-NorthCentralUS/jobs/[[myjob]]?api-version=2016-01-01 HTTP/1.1
Authorization: Bearer
[[my token here]]
Content-Type: application/json; charset=utf-8
Host: management.azure.com
Content-Length: 20
Expect: 100-continue
{"state":"disabled"}
RESPONSE:
{"error":{"code":"BadRequest","message":"Malformed Job Object"}}
Based on their example the JSON passed should work.
Any idea what's going on here? I'm hoping its something simple.
Try the following payload:
{
"properties": {
"state": "disabled"
}
}
Related
I upgraded a .net core 1 project to .net core 2. Everything is working great however my POST method won't return any data. There is no payload. I must be missing something simple.
The API does receive what I send it, so no issues there. But there is nothing in the response (using Chrome and IE dev tools), no matter what I try.
Here are the response headers:
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Content-Type: application/json; charset=utf-8
Content-Encoding: gzip
Server: Kestrel
Access-Control-Allow-Origin: *
X-SourceFiles: =?UTF-8?B?
For instance this returns no payload:
[HttpPost]
public IActionResult PostOrder([FromBody]OrderDto dto)
{
return new OkObjectResult(dto);
}
Caching policy was setting "Location" to none and "NoStore" to true. Removing this policy solved the issue.
I am writing integration test cases where I need to mock web service. I will have a dictionary that maps requests to fake responses. The IEqualityComparer<HttpRequestMessage> is suitably overloaded to treat similar requests as same. To populate the dictionary, I am planning to store request messages in raw format in test files. Copying sample file content below:
POST https://example.com/api/users HTTP/1.1
Prefer: return=representation
Authorization: Bearer BearerToken
Content-Type: application/json; IEEE754Compatible=true
Host: example.com
Content-Length: 23
Expect: 100-continue
Accept-Encoding: gzip, deflate
{"fullname":"John Doe"}
Is it possible to translate the same into HttpRequestMessage object? I do not want to use string as key for dictionary since that would cause false alarms when request message does not significantly differ. Please note that I do not have an option to add a new NuGet package to the project.
I'm having a heck of a time getting Cors working with Web Api. I just created the Web Api with the default template that comes with visual studio 2015. The only changes i made are:
Install-Package Microsoft.aspnet.webapi.cors
In WebApiConfig.cs::Register(HttpConfiguration config):
var cors = new EnableCorsAttribute(
origins: "*",
headers: "*",
methods: "*");
config.EnableCors(cors);
I made the POST method in the values controller async:
public async Task Post(Guid id)
I added a small amount of logic to the post method.
I'm calling the Web Api from another project in my solution:
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("My-GUID",streamProvider.Guid.ToString());
var response = await client.PostAsXmlAsync("http://localhost.fiddler:2010/api/values", myXmlString);
if (response.StatusCode != HttpStatusCode.Created)
{
throw new HttpResponseException(HttpStatusCode.InternalServerError);
}
}
Request:
POST http://localhost:2010/api/values HTTP/1.1
TRS-GUID: 2ca71b41-9e78-4216-a013-e45c6fd6cb4c
Content-Type: application/xml; charset=utf-8
Host: localhost:2010
Content-Length: 183
Expect: 100-continue
Connection: Keep-Alive
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/"><?xml version="1.0" encoding="utf-8"?>
<root>
<MbrId>22</MbrId>
</root></string>
Response:
HTTP/1.1 405 Method Not Allowed
Cache-Control: no-cache
Pragma: no-cache
Allow: GET
Content-Type: application/xml; charset=utf-8
Expires: -1
Server: Microsoft-IIS/10.0
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?Qzpcc291cmNlXEFzeW5jRmlsZVVwbG9hZERlbW9cc3JjXEFwcFxhcGlcdmFsdWVz?=
X-Powered-By: ASP.NET
Date: Thu, 08 Oct 2015 14:33:08 GMT
Content-Length: 93
<Error><Message>The requested resource does not support http method 'POST'.</Message></Error>
Like i said i've made minimal changed and am running this through IIS express locally. I've been googling around and trying a few things but nothing seems to work. I tried adding the cors options as attributes but it resulted in the same thing. I also seen one post suggesting '*' wasn't in the original spec so i tried by using the methods specfically (POST, PUT, GET) but that didn't work either.
Edit:
Does this have anything to do with the 'preflight' request? I only notice the POST request in fiddler. I don't see it sending an 'options' request across. If this is the issue shouldn't httpclient handle this automatically?
Answer
Thanks goes out to Darrel for the answer. As you can tell the error message coming back was really misleading and definitely sounded like a CORS problem but it wasn't. I never realized CORS was only for the browser. Like Darrell said it was a routing problem. I put a Guid as a POST parameter which caused no route to be matched. To bad the error message coming back couldn't be a little more useful.
There are no cross-origin restrictions for HttpClient. It is purely a web browser constraint. You do not need to implement CORS for HttpClient requests.
Try making the POST request via fiddler and see if that works. I suspect you may just have a routing problem.
I Use below REST call to get the access token from WMS, the problem is, some times it works sometimes it gives error "A server with the specified hostname could not be found", Everything is same but the output is random, why this happens ? I'm using c# console project to make this request.
POST https://wamsprodglobal001acs.accesscontrol.windows.net/v2/OAuth2-13 HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: wamsprodglobal001acs.accesscontrol.windows.net
Content-Length: 120
Expect: 100-continue
Connection: Keep-Alive
Accept: application/json
Body:grant_type=client_credentials&client_id=ams_account_name&client_secret=URL_encoded_ams_account_key&scope=urn%3aWindowsAzureMediaServices
I'm responsible for updating a client-side API using WCF. This is because of changes to the API on the server (an outside company). When I get the response, my client-side throws an exception. Using Fiddler, I came up with the following problem: a duplicate Content-Type.
HTTP/1.1 200 OK
Date: Thu, 05 Jan 2012 21:15:16 GMT
Connection: close
Content-Type: text/xml; charset=utf-8
Content-Type: text/xml; charset=UTF-8
Content-Length: 538
...
Using Fiddler, I removed the extra Content-Type, and the client continued happily. So, I wrote an IClientMessageInspector, with the intention of capturing the response and removing the duplicate. And therein lies my issue. My IClientMessageInspector gets a call to BeforeSendRequest, but not one to AfterReceiveRequest.
Is there some place other than AfterReceiveRequest that I should be handling my task of removing the extra Content-Type? Am I barking up the wrong tree altogether?