Microsoft Java graph sdk if-none-match header does not work - microsoft-graph-api

i am using microsoft graph java sdk version 5.32.0 and making a call to get drive item , i am also provding etag so that if item is not modified i get a 304 exception , but i never get an exception eventhough item is not modfied and same etag is returned , any issue is there in the below code which is causing this?
var ho = new HeaderOption("if-none-match","{CE8370C2-65E6-4AF5-8B4A-E02C8A29C081},6");
var options = new ArrayList<Option>();
options.add(ho);
InputStream driveItem = _userClient.drives().byId("b!XSQmjmdVB0qX4G0WHdLwiuszVcK2AgdInZpWIonRDSyw0hXMWgo8T6LY2EqFsRND")
.items("01PK4R276COCB45ZTF6VFIWSXAFSFCTQEB").content().buildRequest(options).get();

Related

Get Response Headers from Microsoft Graph Client

I'm using an old version of Microsoft.Graph (v1.15) and I am trying to check the response headers when calling MS Graph Client.
Am I doing this the right way? Or is there a smarter way to fetch the Headers?
var request = new HttpRequestMessage(HttpMethod.Get, graphClient.Groups.RequestUrl);
var response = await graphClient.HttpProvider.SendAsync(request).ConfigureAwait(false);
Console.WriteLine(response.Headers.ToString());
Ideally I don't want to create HttpRequestMessage, and make the API call directly while also getting the response headers, but I was not able to find a way to fetch the headers with the returned variable below.
await graphClient.Groups.Request().GetAsync().ConfigureAwait(false);
I read in the latest v4 release, there is .GetResponseAsync() which makes retrieving headers easier, but it's not a stable release yet.

How can i get "https://artists.youtube.com/charts/tracks?hl=tr " this page source code with C#?

I use this code:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://artists.youtube.com/charts/tracks?hl=tr");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
But I cant get source code. Everytime I get this error:
Your browser isn't supported :( YouTube ArtistHub requires a browser which supports modern web standards.
How can I get this page's source code?
Hell pal,
I would do this in webclient rather than webrequest.
WebClient wc = new WebClient;
String source = wc.DownloadString(URL)
The variable source should have the source code for the page

No HTTP resource was found that matches the request

I tried to replace the Page content using Microsoft Graph like this:
MultipartFormDataContent form = new MultipartFormDataContent();
form.Add( some stream contents );
var formdatastream = form.ReadAsStreamAsync();
graphClient.Users[userPrincipalName]
.Onenote
.Pages[onenotepage.Id]
.Content
.Request()
.PutAsync<OnenotePage>(formdatastream);
It returns No HTTP resource was found that matches the request, which implies that it does not accept an HTTP PUT request.
Clearly, it is saying it accepts HTTP Patch so maybe the .Net library needs to be changed?
This is a known issue and is a result of a mismatch of the service definition and the service behavior.
If you search for 'onenoteupdatepage' in the OneNote SDK tests, you can see one possible workaround for how to replace an existing page.
To update the OneNote API, you need to trigger a PATCH request like so:
PATCH https://graph.microsoft.com/v1.0/me/onenote/pages/{id}/content
{JSON PAYLOAD}
Perhaps that's not what the SDK is doing?

502 Bad Gateway on POST/PUT Web API Calls from ASP.NET Core MVC

I'm getting strange errors in ASP.NET Core when calling Web API that I have created for the application. GET requests go through fine and return all of the data that they should, but my POST/PUT commands all return a 502, specifically from the MVC application. I can call the API's from Postman and get a proper response and the object is created in the database.
502 - Web server received an invalid response while acting as a
gateway or proxy server. There is a problem with the page you are
looking for, and it cannot be displayed. When the Web server (while
acting as a gateway or proxy) contacted the upstream content server,
it received an invalid response from the content server.
I am impersonating an Integrated Windows Login with the following code for all web requests to the API:
async Task Action()
{
response = await _service.CreateIncident(model);
}
await WindowsIdentity.RunImpersonated(identity.AccessToken, Action);
CreateIncident(model):
using (var client = new HttpClient(new HttpClientHandler { UseDefaultCredentials = true }))
{
var newIncident = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");
var response = await client.PostAsync(hostUri, newIncident);
return response;
}
There is also one GET Request that I make through Ajax to get an incremented ID to display to the user before they create their new Incident that returns a 502 Bad Gateway as well. Is this an IIS Setting that is incorrect?
If you use WindowsIdentity.RunImpersonated and an asynchronous function, it will not work. You must be synchronous when doing non-GET requests. I have updated my GitHub issue, I'm hoping to get this bug addressed. If you are a future visitor to this topic, you can see where this ended up here.
I think it also depends on the size of the data. Smaller packages work, larger ones don't.

Does the TFS Rest API support gzip encoding?

This is the REST API used to connect with Visual Studio Team Services (was Visual Studio Online), and on-premise TFS. I would like to set the headers so I can compress my requests, but the API documentation does not specify that gzip is supported. I'm hoping somebody might have experience.
using (var wc = new WebClient())
{
wc.Credentials = TfsCredentials;
wc.Headers[HttpRequestHeader.ContentEncoding] = "gzip";
wc.Headers[HttpRequestHeader.ContentType] = "application/json";
var gzipByteArray = GZipBytes(serializedJson);
var uploadResponse = wc.UploadData(repoUri, gzipByteArray);
return Encoding.UTF8.GetString(uploadResponse);
}
Response is a 400, with the following error message:
The body of the request contains invalid Json. Parameter name: contentStream
I cannot find any documentation about this either. But I tested it with and without gzip compress from curl. The size of response is indeed compressed with gzip and the response can be decompressed correctly. So it should be supported.

Resources