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

System.Net.Http.HttpRequestException: Response status code does not indicate success: 400 (Bad Request) #20

Open
sambit19 opened this issue Oct 22, 2018 · 4 comments

Comments

@sambit19
Copy link

InnerException	{System.Net.Http.HttpRequestException: Response status code does not indicate success: 400 (Bad Request).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at WebHDFS.WebHDFSClient.<WriteStream>d__4.MoveNext() in C:\Users\sambit\workspace\webhdfs-dotnet\WebHDFSExample\WebHDFSClient.cs:line 96
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at WebHDFS.WebHDFSClient.<UploadFile>d__3.MoveNext() in C:\Users\sambit\workspace\webhdfs-dotnet\WebHDFSExample\WebHDFSClient.cs:line 65}	System.Exception {System.Net.Http.HttpRequestException}

I do not have .Net framework 4.7 and 4.7.1 on my machine so I removed these two targets in the csproj and ran it, got this exception.

I got this exception when I run the WebHDFS.Example code.

@risdenk
Copy link
Owner

risdenk commented Oct 23, 2018

I'm assuming this is related to PR #19 and this is after you added your change for EnsureSuccessStatusCode()?

@sambit19
Copy link
Author

What changes are to be added to EnsureSuccessStatusCode()?
The only change I made is added
_httpClient.DefaultRequestHeaders.ExpectContinue = false;

to WebHDFSClient code.

But I still get the same error?

Can you share what changes needs to be done for EnsureSuccessStatusCode()?

@sambit19
Copy link
Author

In my case the exeception is coming before EnsureSuccessStatusCode() is invoked.

response2 = {StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.NoWriteNoSeekStreamContent, Headers:{ Connection: close Date: Tue, 23 Oct 2018 15:54:51 GMT Server: Apache-Coyote/1.1 Content-Length: 1122 Content-Type: text/html; charset=utf-8}}

@sambit19
Copy link
Author

So these are the curl equivalents which is working to upload the file
Step 1:
curl -i -k --negotiate -u : -X PUT "https://host:14000/webhdfs/v1/user/pasted-image-0-5.png?op=CREATE&overwrite=true"

Step 2:

curl -i -k --negotiate -u : -X PUT -T pasted-image-0-5.png -H 'Content-Type: application/octet-stream' "https://host:14000/webhdfs/v1/user/pasted-image-0-5.png?op=CREATE&data=true&overwrite=true"

How do I set the following in the code:

  1. -u : anyuser(option is mandatory when the user name is not specified instead, a Kerberos established user (via kinit) is used.)
  2. -H --> specify the content type
  3. -k for ignoring the certificates(the better would be a way to add the certificates)
  4. --negotiate (It will be good to have flexibility to set the authentication manager)

I am new to C#, so this is bit tricky. Appreciate your guidance.

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

2 participants