Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled exception. System.Net.Http.HttpRequestException: 405 - Method Not Allowed #71

Open
fadyanwar opened this issue Jan 19, 2022 · 3 comments

Comments

@fadyanwar
Copy link

Hi, I'm getting the below error using the Nuget package while running an IPFS node locally.

$ dotnet run
Unhandled exception. System.Net.Http.HttpRequestException: 405 - Method Not Allowed

at Ipfs.Http.IpfsClient.ThrowOnErrorAsync(HttpResponseMessage response)
at Ipfs.Http.IpfsClient.DownloadAsync(String command, CancellationToken cancel, String arg, String[] options)
at Ipfs.Http.FileSystemApi.ReadAllTextAsync(String path, CancellationToken cancel)
at $.<

$>d__0.MoveNext() in /home/fady/ipfstest/Program.cs:line 6
--- End of stack trace from previous location ---
at $.(String[] args)

I'm using your sample code as per instructions on the readme page

using Ipfs.Http;

var ipfs = new IpfsClient();

const string filename = "QmXarR6rgkQ2fDSHjSY5nM2kuCXKYGViky5nohtwgF65Ec/about";
string text = await ipfs.FileSystem.ReadAllTextAsync(filename);

@jurilents
Copy link

jurilents commented Jan 27, 2022

Problem is caused by a breaking change in the HTTP interface of the IPFS daemon. Since version 0.5.0, all the endpoints accept only POST requests.

And this is my temp solution for this issue - override default methods using PostDownloadAsync instead of DownloadAsync (certainly not the best choice, but still works for me) 😅

public class CustomIpfsFileReader
{
	private readonly IpfsClient ipfs;

	internal CustomIpfsFileReader(IpfsClient ipfs)
	{
		this.ipfs = ipfs;
	}

	public async Task<string> ReadAllTextAsync(string path, CancellationToken cancel = default)
	{
		await using Stream data = await this.ReadFileAsync(path, cancel);
			using StreamReader reader = new StreamReader(data);
			return await reader.ReadToEndAsync();
	}

	public Task<Stream> ReadFileAsync(string path, CancellationToken cancel = default)
	{
		return this.ipfs.PostDownloadAsync("cat", cancel, path);
	}

	public Task<Stream> ReadFileAsync(string path, long offset, long length = 0, CancellationToken cancel = default)
	{
		return this.ipfs.PostDownloadAsync("cat", cancel, path, $"offset={offset}", $"length={length}");
	}

	public Task<IFileSystemNode> ListFileAsync(string path, CancellationToken cancel = default)
	{
		return this.ipfs.FileSystem.ListFileAsync(path, cancel);
	}

	public Task<Stream> GetAsync(string path, bool compress = false, CancellationToken cancel = default)
	{
		return this.ipfs.FileSystem.GetAsync(path, compress, cancel);
	}
}

@Andrem19
Copy link

That helped. Thanks

@Arlodotexe
Copy link

Arlodotexe commented Sep 27, 2022

@jurilents @Andrem19 @fadyanwar This library is no longer being maintained. The community has taken ownership of a fork in the IPFS Shipyard, and are keeping it maintained and updated.

See #72 for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants