senkd
senkd
CC#
Created by Relevant on 1/17/2024 in #help
SFTP through a proxy server
Have you tried setting up an SSH port forward (via the intermediary server, i.e. local port 1234:ip behind intermediary:22), and then making your SFTP connection via the port forward?
6 replies
CC#
Created by senkd on 1/17/2024 in #help
Graph API - HttpClient returns 404, but curl (and Graph Explorer) for same request works?
The Graph API will return a conversationThreadId immediately on creation, but it can take up to 2 minutes (from my testing) before the replies can be posted. From my testing only ~10 out of ~2000 replies needed to wait the full 2 minutes. Many worked immediately, some needed 15 seconds, others needed 1 minute. It would've been great if I didn't need to go through all of this manual effort to figure this out...
3 replies
CC#
Created by senkd on 1/17/2024 in #help
Graph API - HttpClient returns 404, but curl (and Graph Explorer) for same request works?
Ok, well, it seems like it was an issue related to timing...
c#
var token = await GetUserTokenAsync();

using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
using (var content = new StringContent(body, Encoding.UTF8, "application/json"))
{
var postUrl = $"https://graph.microsoft.com/v1.0/groups/{groupId}/threads/{threadId}/reply";

var resp = await client.PostAsync(postUrl, content);

if (resp.StatusCode == HttpStatusCode.NotFound)
{
Console.WriteLine("Info: Retrying post-reply (after 15 seconds), Graph returned 404...");
await Task.Delay(TimeSpan.FromSeconds(15));
resp = await client.PostAsync(postUrl, content);
}
if (resp.StatusCode == HttpStatusCode.NotFound)
{
Console.WriteLine("Info: Graph still says this doesn't exist. Waiting 45 more seconds and trying again...");
await Task.Delay(TimeSpan.FromSeconds(45));
resp = await client.PostAsync(postUrl, content);
}
if (resp.StatusCode == HttpStatusCode.NotFound)
{
Console.WriteLine("Info: Graph is really sure that this doesn't exist, but we'll try again in 60 seconds...");
await Task.Delay(TimeSpan.FromSeconds(60));
resp = await client.PostAsync(postUrl, content);
}
if (!resp.IsSuccessStatusCode)
{
Console.WriteLine($"Error: Unable to post reply to group {groupId} thread {threadId}. The server said {await resp.Content.ReadAsStringAsync()}");
String curlCommand = $"curl -i -X POST -H \"Authorization: Bearer {token}\" -H \"Content-Type: application/json\" -d '{body}' \"{postUrl}\"";
Console.WriteLine($"Try this with curl: {curlCommand}");
}
Console.WriteLine("Posted!");
}
}
c#
var token = await GetUserTokenAsync();

using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
using (var content = new StringContent(body, Encoding.UTF8, "application/json"))
{
var postUrl = $"https://graph.microsoft.com/v1.0/groups/{groupId}/threads/{threadId}/reply";

var resp = await client.PostAsync(postUrl, content);

if (resp.StatusCode == HttpStatusCode.NotFound)
{
Console.WriteLine("Info: Retrying post-reply (after 15 seconds), Graph returned 404...");
await Task.Delay(TimeSpan.FromSeconds(15));
resp = await client.PostAsync(postUrl, content);
}
if (resp.StatusCode == HttpStatusCode.NotFound)
{
Console.WriteLine("Info: Graph still says this doesn't exist. Waiting 45 more seconds and trying again...");
await Task.Delay(TimeSpan.FromSeconds(45));
resp = await client.PostAsync(postUrl, content);
}
if (resp.StatusCode == HttpStatusCode.NotFound)
{
Console.WriteLine("Info: Graph is really sure that this doesn't exist, but we'll try again in 60 seconds...");
await Task.Delay(TimeSpan.FromSeconds(60));
resp = await client.PostAsync(postUrl, content);
}
if (!resp.IsSuccessStatusCode)
{
Console.WriteLine($"Error: Unable to post reply to group {groupId} thread {threadId}. The server said {await resp.Content.ReadAsStringAsync()}");
String curlCommand = $"curl -i -X POST -H \"Authorization: Bearer {token}\" -H \"Content-Type: application/json\" -d '{body}' \"{postUrl}\"";
Console.WriteLine($"Try this with curl: {curlCommand}");
}
Console.WriteLine("Posted!");
}
}
3 replies