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

What kind of media type does StringContent constructor support? #4487

Closed
chucklu opened this issue Feb 24, 2018 · 2 comments
Closed

What kind of media type does StringContent constructor support? #4487

chucklu opened this issue Feb 24, 2018 · 2 comments

Comments

@chucklu
Copy link

chucklu commented Feb 24, 2018

StringContent(String, Encoding, String)
The third parameter is mediaType String
The media type to use for the content.

When I pass "application/base64" as the mediaType, I got the following error message.

new StringContent(fileContent, Encoding.UTF8, "application/base64")

The best overloaded method match for 'System.Net.Http.StringContent.StringContent(string, System.Text.Encoding, string)' has some invalid arguments
ExceptionType:Microsoft.CSharp.RuntimeBinder.RuntimeBinderException
Assembly:Anonymously Hosted DynamicMethods Assembly
Method:System.Net.Http.StringContent CallSite.Target(System.Runtime.CompilerServices.Closure, System.Runtime.CompilerServices.CallSite, System.Type, System.Object, System.Text.Encoding, System.String)

I find the media type from this page.
I am not sure if this class can support all media types.
I wonder if you guys can list how many media types are supported for StringContent's constructor.

@svick
Copy link
Contributor

svick commented Feb 24, 2018

The error message talks about overload resolution, which means you're using dynamic and types of parameters you passed in couldn't be matched to any overload of the StringContent constructor.

I'm pretty sure this is because fileContent is not a string, which it has to be according to the method signature. This has nothing to do with the mediaType you used.

@chucklu
Copy link
Author

chucklu commented Feb 26, 2018

@svick Thanks, I forgot to convert dynamic type to string.

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