Always have error "The ObjectContent 1 type failed to serialize the response body..." |
Change IEnumerable<Message> to List<Message>
public IEnumerable<Message> GetAllMsg()
{
return repo.GetAll();
}
to
public List<Message> GetAllMsg()
{
return repo.GetAll();
}
UPDATE:
But beware of getting OutOfMemoryException because this method will store
all Message objects in local memory so you have to implement some kind of
paging.
|
the content type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8' |
You need to use the WebServiceHostFactory, instead of the regular
ServiceHostFactory in your code. That will configure the endpoint with the
appropriate binding (webHttpBinding) and behavior (webHttp) to honor the
[WebInvoke] attribute.
<serviceHostingEnvironment >
<serviceActivations>
<add factory="System.ServiceModel.Activation.WebServiceHostFactory"
relativeAddress="./wsccc1/wscccService.svc"
service="service.wservice"/>
</serviceActivations>
</serviceHostingEnvironment>
|
WCF client talking to Java WS, exception: The content type application/xop+xml; type="application/soap+xml" of the response message |
Try setting the message encoding in the binding configuration to
messageEncoding="Mtom" and basicHTTPBinding instead of wsHTTP one...
Hope it helps!
|
ClientRequest, how to serialize POJO's to json data correctly? could not find writer for content-type application/json type: |
Problem solved, unfortunately I haven't included all necessary 3rd party
libraries to the projects build path. Finally I added the following jars:
jackson-core-asl-1.6.3.jar
jackson-jaxrs-1.6.3.jar
jackson-mapper-asl-1.6.3.jar
jackson-xc-1.6.3.jar
resteasy-jackson-provider-2.2.1.GA.jar
This example brings the strength of Maven to the front. With Maven there is
only one entry necessary to fulfill these dependencies.
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>2.2.1.GA</version>
</dependency>
|
Spring Android Get Request implementation : Could not extract response: no suitable HttpMessageConverter found for response type and content type |
Your server returns an XML content but says it returns HTML content
(content type is text/html according to the error message) and thus the
parsing failed. You need to make sure your server returns something like
text/xml and also that you have the correct converters in you rest template
object.
Edit: Try to add this message converter. Put it first (before
StringHttpMessageConverter and SourceHttpMessageConverter)
Jaxb2RootElementHttpMessageConverter jaxbMessageConverter = new
Jaxb2RootElementHttpMessageConverter();
List<MediaType> mediaTypes = new ArrayList<MediaType>();
mediaTypes.add(MediaType.TEXT_HTML);
jaxbMessageConverter.setSupportedMediaTypes(mediaTypes);
messageConverters .add(jaxbMessageConverter);
|
Flask - How do I read the raw body in a POST request when the content type is "application/x-www-form-urlencoded" |
You can get the post data via request.form.keys()[0] if content type is
application/x-www-form-urlencoded.
request.form is a multidict, whose keys contain the parsed post data.
|
Header Content Type Charset UTF-8 with BOM |
There's absolutely no need to include a BOM in an HTML file. (If it really
includes different encodings, then a UTF-8 BOM would be broken, so it
sounds like you're a bit confused.)
If you expect the file to be saved to disk and used in places where UTF-8
isn't expected, you could add a meta element to indicate the encoding as
well:
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
If in fact you are using a different encoding than UTF-8, then rather than
a BOM, just change the value in the meta attribute.
If you really must have a BOM in there then you'll need to make sure that
it's first thing you output, e.g.
echo "xEFxBBxBF";
See How can I output a UTF-8 CSV in PHP that Excel will read properly? for
an example where that actually makes sense.
|
C# Http.Response Stream Returns Empty String With application/json Content Type |
It is possible that somewhere in the request pipeline Request.InputStream
was already read. In this case its position is already at the end, and of
course ReadToEnd reads nothing and returns empty string. This is the root
of the problem in our case. Resetting the position fixes the problem:
[HttpPost]
[ValidateInput(false)]
public ActionResult StreamDebug2(string someParameter)
{
string postbody = "";
Request.InputStream.Position = 0;
using (StreamReader reader = new StreamReader(Request.InputStream,
Encoding.UTF8))
{
postbody = reader.ReadToEnd();
}
return this.Content(postbody);
}
Update. After a little bit of digging into sources I also found why the
position was shifted. It turns out that Request.InputStream is used in
JsonValueProviderFactory in the following manner
|
Jersey and @FormParam not working when charset is specified in the Content-Type |
I think it's a bug.
There's a pull request open to support this use case:
https://github.com/jersey/jersey/pull/24/files
In the meantime I'd suggest to use a filter to remove the offending
encoding.
EDIT as per OP comments
I'm thinking on something along these lines:
@Provider
@PreMatching
public class ContentTypeFilter implements ContainerRequestFilter{
@Override
public void filter(ContainerRequestContext requestContext)
throws IOException {
MultivaluedMap<String,String>
headers=requestContext.getHeaders();
List<String>
contentTypes=headers.remove(HttpHeaders.CONTENT_TYPE);
if (contentTypes!=null && !contentTypes.isEmpty()){
String contentType= contentTypes.get(0);
String sanitizedContentType=c
|
How to consume a webservice expecting "application/octet-stream" as Content Type and base64Binary as Type? |
It worked by leaving out the type for the dataHandler:
DataSource dataSource = new ByteArrayDataSource(myDoc.getDocument(),
"application/pdf");
DataHandler dataHandler = new DataHandler(dataSource);
|
How to create an endpoint that accepts any content type in the request body using ASP.Net Web API |
You can bypass formatters entirely by reading the content yourself. Here's
an example:
public async Task Post()
{
string content = await Request.Content.ReadAsStringAsync();
// Store away the content
}
This doesn't require you to use or define any formatters at all.
|
Serialize complex type as simple type JSON |
import this namespace System.Web.Script.Serialization;
string SerializeObject()
{
var objs = new List<Test>()
var objSerialized = new JavaScriptSerializer();
return objSerialized .Serialize(objs);
}
I use as example a List but you will use your object instead.
|
how to add content-type to Twilio response? |
The Content-Type text/html bit refers to the 502 bad gateway response,
not the actual response coming from your server. Add the "text/xml" content
type to your request (I don't recognize the framework you are using) and
you should be good to go.
To debug your response you can use curl -vvv [URL] until the Content-Type:
text/xml part is present.
|
What format and content-type is the body of a paypal rest access token call? |
Thanks for bringing up the question.
There was a recent change in the /token call and requests for an access
token need to have the content-type set as
application/x-www-form-urlencoded. This is done by default in cURL calls.
Updated docs that include a note about this will be going out very soon.
|
Default x-www-form-urlencoded content type for http request body in web services |
As per the HTTP spec, you can send any content type you like in an HTTP
response as long as you provide the appropriate Content-type header.
The main benefit of JSON and XML over a plain query string is that they
support hierarchies and complex data structures, e.g.:
{"cars":[{"manufacturer":"Ford"}, {"manufacturer":"GM"}]}
or
<cars>
<car>
<manufacturer>Ford</manufacturer>
</car>
<car>
<manufacturer>GM</manufacturer>
</car>
</cars>
These kinds of structures are usually very useful for webservices, and
can't really be achieved with a plain query string.
|
How to parse HTTP request with a missing content type in Express/ NodeJs, by assuming a default content type? |
You have a bunch of options including manually invoking the express
(connect, really) middleware functions yourself (really, go read the source
code. They are just functions and there is no deep magic to confuse you).
So:
function defaultContentTypeMiddleware (req, res, next) {
req.headers['content-type'] = req.headers['content-type'] ||
'application/json';
next();
}
app.use(defaultContentTypeMiddleware);
app.use(express.bodyParser());
|
How to determine the Content-Type in an HTTP Response |
By default, web server looks into file extension and select what kind of
Content Type it should interpret the file as. However, server-side
scripting can send custom header ( e.g. header() function of PHP ) to
override the settings . For example, a JPEG can be interpreted as PNG if
you send Content Type as image/png to web server with the following code:
header('Content-Type: image/png');
For non-file requests, the web server looks into custom header directly.
Web server maps extension with MIME type. As you tag apache, Apache uses
AddType directive to identify file's MIME type, while IIS and other web
servers have similar settings .
|
serialize a non-serializable object of type Type? |
You may not need to serialize Type - consider if serializing full name of
the type (possibly with full name of assembly it coming from to make
loading of the type easier) is enough for your case.
Definitely if you try to create an object of this type in some remote
process just full type name is enough (assuming the other process have
access to assembly implementing the type).
|
How to deserialize JSON with fixed type header and variant type body in C#? |
Is it feasible to solve this problem by using an interface instead of
object, and making use of the "specify known types" version of the
DataContractJsonSerializer (
http://msdn.microsoft.com/en-us/library/bb908209.aspx ) ?
It would look something like
var serializer = new DataContractJsonSerializer(typeof(IMySerializable),
new [] {
typeof(ConcreteSerializable1),
typeof(ConcreteSerializable2)
});
Basically, DataContractSerializer needs context on what you expect it might
serialize/deserialize, it can't infer types from the content of the JSON.
If you don't want to do that you may want to consider a third party library
that will give you m
|
Dexterity Content Type DateTime Issue & How to modify Content Type Values |
not sure about the dateTime issue, but check out indexes, indexing and
custom index to figure out setting titles and description.
to set your title for instance
@indexer(IFormName)
def titleIndexer(obj):
return obj.valueFromForm
grok.global_adapter(titleIndexer, name="Title")
|
Client found response content type of 'multipart/related |
I had similar problems with ASP.NET generated code & settings for
ChangeService (Rational Synergy) WSDL file.
I was also receiving the MIME header along with XML message. Assuming that
you are using a service reference, I had to modify the web.config file with
the following changes
First i had to modify the HttpBinding from basicHttpBinding to
webHttpBinding, add behaviors and configure endpoint.
In the config below changes are marked in BOLD
<bindings>
<!-- basicHttpBinding>
<binding name="ChangeServiceHttpBinding" messageEncoding="Mtom"
/>
</basicHttpBinding -->
<webHttpBinding>
<binding name="ChangeServiceHttpBinding" />
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior n
|
What does Failed to convert property value of type '$Proxy0 to required type means in this case? |
Ok, first thing i see here:
WriterSqlParameterSetter is a ItemPreparedStatementSetter! fine!
But even if you declare:
<beans:property name="amount" value="#{jobParameters[amount]}"/>
<beans:property name="id" value="#{jobParameters[id]}"/>
I don't see theses properties in :
public class WriterSqlParameterSetter implements
ItemPreparedStatementSetter<transactionas>{
public void setValues(transactionas ts, PreparedStatement ps) throws
SQLException {
ps.setDouble(1, ts.GetAmount());
ps.setInt(2, ts.GetID());
}
}
And even if the properties were declared, the ItemPreparedStatementSetter
wont use them since, it takes value from the object received in the writer
(eg. transactionas).
I am trying to see why you need to pass an amount and
|
What does Failed to convert property value of type '$Proxy0 to required type means? |
You don't use the right interface. Your ReaderSqlParameterSetter should
implements PreparedStatementSetter not ItemPreparedStatementSetter
If you look at the impl of JdbcCursorItemReader:
public class JdbcCursorItemReader<T> extends
AbstractCursorItemReader<T> {
PreparedStatement preparedStatement;
PreparedStatementSetter preparedStatementSetter;
String sql;
RowMapper rowMapper;
The property is a PreparedStatementSetter .
If you look at the interface you try to use :
public interface ItemPreparedStatementSetter<T> {
/**
* Set parameter values on the given PreparedStatement as determined from
* the provided item.
* @param ps the PreparedStatement to invoke setter methods on
* @throws SQLException if a SQLException is encountered (i.e. there is no
* need to
|
Why does JQuery NOT selector failed on Type Submit but works on Type Button |
Your code does work, here: http://jsfiddle.net/AstDerek/s5cyk/
What do you expect to happen with the code you are using?
Original answer:
I don't really understand what your code does, but it seems you are trying
to target a button with an :input selector, so your code doesn't work as
you expect. Maybe this selector can do the job:
$('#myForm :input:not(#btnSubmit), #myForm button:not(#btnSubmit)')
|
How to fine control how a SOAP response type is converted into a PHP type? |
You can transform that result in almost anything in PHP via that classmap
feature, but the question is if you should, because the same Soap data
structures are usually used for both requests and responses. Reuse them!
My general approach is to use the classmap feature to map all those
ComplexType structures onto PHP classes. And if that structure does not fit
well to the intended use, I have a mapper step that transforms the result
in PHP.
|
A missing or empty content type header was found when trying to read a message. The content type header is required |
Thanks Vitek Karas MSFT for your suggestion. The issue is sovled by
installing the latest version of WCF Data Services 5.6.0. and thanks to
Maikel who tried in on our dev and was able to solve the issue.
|
send Http request with Content Type application Json on C# |
Assuming you have a class like this to represent the payload,
class Payload
{
public Dictionary<string, string> data { get; set; }
public string consolidationKey { get; set;}
public long expiresAfter { get; set; }
}
you can use HttpClient, like this.
string url = "http://api.amazon.com/messaging/registrations/1234/messages";
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
"Bearer", "token");
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("X-Amzn-Type-Version",
"com.amazon.device.messaging.ADMMessage@1.0");
client.Default
|
Send an html email error content type or mime type |
I have tested this example in my web host and it works perfectly :
<?php
$from = "xxxxx@gmail.com";
$subject = "Confirm Your Email";
$message = "<html><body>";
$message .= "
<center>
<b>You are reiciving this email because you Signed up at
Alphaladys.com</b> <br>
<font color="red">Thank You, $name</font><br>
<b><a
href="alphaladys.com/?71860c77c6745379b0d44304d66b6a13=emailVerify&key=$key">Confirm
Your Email</a></b><br>
</center>
<br><br>© 2013 Copyright | AlphaLadys.Com | All rights
reserved.
";
$message .= "</body></html>";
$headers = "From: " . $from . "
";
$headers .= "Reply-To: ". $from . "
";
$headers .= "MIME-Version: 1
|
send post Https request with Content Type application Json on C# |
Just looking at this quickly it seems like this line of code is wrong.
var result = client.PostAsJsonAsync<Dictionary<string,
Object>>(url, data).Result;
based on fact that you're saying amazon wants the post json to look like
this.
{"data":{"message":"value1","title":"value2"},"consolidationKey":"Some
Key","expiresAfter":86400}
It seems like you should be passing your var content to the post rather
than var data. I.e.
var result = client.PostAsJsonAsync<Dictionary<string,
Object>>(url, content).Result;
|
change Content-type to "application/json" POST method, RESTful API |
Posting a JSON object is quite easy in Angular. All you need to do is the
following:
Create a Javascript Object
I'll use your exact properties from your code.
var postObject = new Object();
postObject.userId = "testAgent2";
postObject.token = "testAgent2";
postObject.terminalInfo = "test2";
postObject.forceLogin = "false";
Post the object to the API
To post an object to an API you merely need a simple $http.post function.
See below:
$http.post("/path/to/api/", postObject).success(function(data){
//Callback function here.
//"data" is the response from the server.
});
Since JSON is the default method of posting to an API, there's no need to
reset that. See this link on $http shortcuts for more information.
With regards to your code specifically, try changing your save metho
|
Struggled with Content-Type "application/x-www-form-urlencoded" in REST webservices |
A copy of the soution (from Sergey)
http://cxf.547215.n5.nabble.com/Consume-quot-application-x-www-form-urlencoded-quot-Content-Type-in-REST-Web-Service-cxf-rsServer-td5730399.html#a5730446
Different solutions are :
have a Form or MultivaluedMap parameter instead of AmountTransaction and
populate AmountTransaction manually
have a custom provider (as you suggested)
use a cxf extension @FormParam("") with AmountTransaction
use JAX-RS 2.0 @BeanParam and have AmountTransaction properties annotated
with FormParam
|
Invalid content type: application/x-www-form-urlencoded on request using httparty |
That should probably be:
data = HTTParty.post(url, :body => request, :headers =>
{"Content-Type" => "application/xml"})
Don't worry about content-length, that's HTTParty's job.
|
Convert drupal 7 content type into code automatically. Content type generator code? |
maybe this can help you.
add hook_install():
please check:
http://yaremchuk.ru/blog/how-create-content-type-drupal-7-programmatically
|
drupal 7 content type and pattern content type |
Although you described it as a pattern this could be done with a reference.
So, a House will have a reference to a House Type Node. Then, the field of
the House Type will be rendered within the House node page (choose
"Rendered entity" as a display formatter). This way you can add any field
latter in the House Pattern node and these will be rendered to your House
Nodes automatically.
You can use the entity_reference module for this task.
|
How to make Laravel return a View's "Content-Type" header as "application/javascript"? |
Laravel lets you modify header information via the Response class, so you
have to make use of it. Remove the header line from your view and try it
like this in your controller:
$contents = View::make('embedded')->with('foo', $foo);
$response = Response::make($contents, $statusCode);
$response->header('Content-Type', 'application/javascript');
return $response;
|
Target tags in CSS, in Content-type application/xhtml+xml for earliers internet explorer |
Well you could transform all elements to plain HTML without namespace doing
e.g.
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
Then you need also need
<xsl:template match="@* | comment() | text() |
processing-instruction()">
<xsl:copy/>
</xsl:template>
to ensure other nodes are copied unchanged.
So all together you get
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@* | com
|
Order of request parameters for content-type application/x-www-form-urlencoded in Spring MVC |
Your message converter does not work with the native request but with a
HttpInputMessage parameter. That is a Spring class.
The inputMessage.getBody() is were your problem arises. By default, a
ServletServerHttpRequest (another Spring class) is used which has something
like this in its getBody() method:
public InputStream getBody() throws IOException {
if (isFormSubmittal(this.servletRequest)) {
return getFormBody(this.servletRequest);
}
else {
return this.servletRequest.getInputStream();
}
}
which delegates to a private implementation like this:
private InputStream getFormBody(HttpServletRequest request) throws
IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Writer writer = new OutputStreamWriter(bos, FORM_CHARSET);
|
jQuery doesn't send post request with content type application/json |
Access Control Origin things.
Setting of Content-Type header in the JavaScript was not allowed by
browser. The solution is to modify the response headers (example in Java):
HttpServletResponse hresp = (HttpServletResponse) resp;
hresp.addHeader("Access-Control-Allow-Origin", "*");
hresp.addHeader("Access-Control-Allow-Headers",
"X-Requested-With,Content-Type");
It is not jquery-specific, but it applies to every AJAX request as well
(Dojo or plain javascript).
|
Rails: Empty params when do ajax post with content-type = application/json |
Well, after a long research , I figure it out that inside of my profiles'
initialize/mime_types.rb , they added
Mime::Type.register "application/json", :mobile
Dig into a bit , I can see that Rails uses the mime types to parse the
request body , in this case , application/json is overriden , and Rails
can't use the Json parse strategy to parse the request body into params
hash, that's why it's empty
Backbone.emulateJSOn will set another content-type instead of
application/json, that's why Rails still can understand this Mime Type, and
has correspond parse strategy for it , but since it's not the JSON strategy
, so the params is not in JSON format
Json parse strategy ( from Rails source )
when :json
data = request.deep_munge ActiveSupport::JSON.decode(request.body)
request
|
LINQ To XML error: type of the expression in the select clause is incorrect. Type inference failed in the call to 'Select' |
The problem is with your closing parenthesis - you've got it at the end of
the ToList() call, when you meant to put it at the end of the object
initializer. Also, you're not actually calling the method - you're just
specifying a method group. Finally, you can let type inference work out the
type argument for you:
List<Data> dogs = (from q in doc.Descendants("dog")
where (string)q.Attribute("name") == dogName
select new Data
{
name = q.Attribute("name").Value,
breed = q.Element("breed").Value,
sex = q.Element("sex").Value
}).ToList();
|