How to disable the parent window control in C# web api - c#

I am using a web api which takes XML as in body content, but Now i want to send Json in body content.
But when i have tried sending json in body it is giving me parent window control error.
Any Suggestion will be helpful for me.
Thanks in advance !!

Nitesh, to easily help you, kindly share a code snippet or snapshot of the code you are trying to execute.
Alternatively, from the abstract point of view, I suggest that you add "Content-Type" header key with a value of "application/json" to specify to the API server that the content is of a JSON format.
For more information about Content Type, I recommend reading the article about content-types https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type
Thank you

Related

ASP.NET Web API and UTF16 encoding

I have a ASP.NET web API running and have a client running into following issue:
{"model":["Unable to translate bytes [E9]
at index 300 from specified code page to Unicode."]}
The exception appears to be happening during model binding, which is the default nothing custom on my end.
The client is also running .NET and they say that the content is being sent over as UTF16....but they are not including HTTP header to indicate that. Up until they began having special characters in their content everything worked great.
My question is how to deal with this. Initially I was going to add a DelegateHandler which would detect this client and somehow set content-type/charset to UTF16 but that isn't panning out. I then thought I could transcode the request body to UTF8 from within DelegateHandler but have read that modifying content in handler is not possible or recommended.
Since the issue appears to be during model binding I'm wondering if implementing a custom model binder would be in order?
Thanks for any help!
The default encoding used by the built-in formatters is UTF-8. You can easily change it to UTF 16. You can change this on a per-formatter basis by changing the SupportEncodings property on the MediaTypeFormatter class.
This link can help you.

how to download a partial web page using .net

We are downloading a full web page using System.Net.WebClient class. But we only want less than half of the page. So is there a way to download a portion of the page, say 1/3rd, half etc of a page using .net library so that We can save the network bandwidth and the space? If so, please throw your ideas, thanks.
You need to provide an "Accept-Ranges header" to your GET or POST request. That can be done by using the AddRange method of your HttpWebRequest:
HttpWebRequest myHttpWebRequest =
(HttpWebRequest)WebRequest.Create("http://www.foo.com");
myHttpWebRequest.AddRange(0,100);
That would yield the first 100 bytes. The server, however, needs to support this.
The sort answer is not unless the web app supports some way to tailor it's response to what you want it to return.
This could take the form of a
query string parameter
header field value
The simplest way to add this would be a query string parameter and when detected write out the necessary HTML to the response object. If you are unable to make changes to the web app then you won't be able to control how much of a page is returned to you.
You might want to read up on how HTTP works since the question and it's answer relies upon this. Specifically the Header Definition should be helpful.

Display image while populating c# object from web service

response = service.getInfo(request);
How can I display an image while my response object is being populated? Service is a web service located on another server that I have no control over.
Any help is greatly appreciated.
Here is one way to do it.
The bottom line is that you will need some asynchronous process going on. And that implies AJAX. The library or methodology you use is up to you.

How Design A Software to InputData In WebForm Automatically?

I Want Create A Software to Input Data in WebForms Automatically (like Robot) And Accept Input Data.
How I Can Create this Software in C# (Windows Application)?
what Technologies Must Be Used?
What OpenSource Project Exist for use?
Sample Code And etc...
Please Help Me
I hope you're doing something within the acceptable terms of use with the content you automatically post. Ie. you do not ask how to create yet another spam bot...
To grab the HTTP form you can use WebRequest. This returns the content of the page (including the form) as a response stream. You can then parse the response using HtmlAgility pack, for the forms you are interested. Once you know the forms and fields in the page, you can set values for the fields and post a response, again using a WebRequest but changing the method to POST and encoding the reponse fields as application/x-www-form-urlencoded content, see How to: Send Data Using the WebRequest Class.
This method is using almost the most basic building blocks, going lower level than this would mean using sockets and formating the HTTP request yourself. At this low level you'll have a great deal of freedom and flexibility on how to parse the form and send back the request, at the cost of actually having to understand how WebForms and HTTP work.

How to get an image file extension from the web when it has been stripped?

The link below is an image URL where the extension has been stripped. I assume this is being done with content negotiation tools. I know that it's a GIF having viewed the HTML meta data with Firebug. What I would like to know is a simple way working in C# on .NET, how would I get the file type of this URL?
http://ep.yimg.com/ca/I/yhst-20493720720238_2066_63220718
With most image URLs it's easy. One can use string functions to find the file type in the URL.
Ex. /imageEx.png
You're going to have to make an HTTP HEAD request, and then check the Content-Type on the response. I can't recall whether System.Net.HttpWebRequest supports HEAD requests, but that would be the place to start.
Alternatively, you could perform a full GET request, but that could have performance implications if all you need to know is Content-Type.
You would have to read in the image and look for 'magic numbers' which can tell you what the file type really is. Here is an incomplete example of what I am talking about:
http://www.garykessler.net/library/file_sigs.html
EDIT: OK, you don't have to do it this way in this context. I am not a web guy, so this is how I would have approached it :-)
See Content-Type. You might also want to read up on content type spoofing.

Categories