PostAsJsonAsync posts as text/html onto server and not as JSON

I'm trying to post a JSON string on a PHP page using Async methods as follows:
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
namespace test_http
class Product
public string Name { get; set; }
public double Price { get; set; }
public string Category { get; set; }
class Program
static void Main()
RunAsync().Wait();
static async Task RunAsync()
using (var client = new HttpClient())
client.BaseAddress = new Uri("http://localhost/ABC/products.php");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// HTTP GET
HttpResponseMessage response = await client.GetAsync("products/1");
Console.WriteLine(response.ToString());
if (response.IsSuccessStatusCode)
Product product = await response.Content.ReadAsAsync<Product>();
Console.WriteLine("{0}\t${1}\t{2}", product.Name, product.Price, product.Category);
// HTTP POST
var gizmo = new Product() { Name = "Gizmo", Price = 100, Category = "Widget" };
response = await client.PostAsJsonAsync(client.BaseAddress, gizmo);
Console.WriteLine(response.ToString());
if (response.IsSuccessStatusCode)
Uri gizmoUrl = response.Headers.Location;
// HTTP PUT
gizmo.Price = 80; // Update price
response = await client.PutAsJsonAsync(gizmoUrl, gizmo);
Console.WriteLine(response.ToString());
// HTTP DELETE
response = await client.DeleteAsync(gizmoUrl);
Console.WriteLine(response.ToString());
I get a 200 status OK for POST, PUT and DELETE operations on the console window. But the PHP page displays nothing being posted. PHP code:
<?php
var_dump(json_decode(file_get_contents('php://input')));
?>
I figured out that the content-type of data being being posted is shown as 'text/html' in the console instead of 'application/json' and hence the PHP is unable to recognise the POST. But i dont know what i'm doing wrong here. could someone please help out?
Thanks,
Revathy

You could serialize the object your self, and post it with the correct Media-Type:
HttpClient client = new HttpClient();
StringContent content = new StringContent(
JsonConvert.SerializeObject(gizmo),
UTF8Encoding.UTF8,
"application/json");
var response = await client.PostAsync(requestUri, content);

Similar Messages

  • Escrow the recovery key in DB server and not in AD when removable drive is encrypted.

    Is there any way to escrow the recovery key in the database server and not in AD when removable drive (USB drive) is encrypted via manage-bde command line? The data recovery agent is not enabled in our organization. 
    "Choose how bitlocker protected removable Drives can be recovered" for removable drives is disabled in our Group policy also.
    Please advise. Thank you.

    As far as I am concerned, you cannot do that when you are using the command line "Manage-bde".
    The reason is because, the manage-bde command line parameters doesn't support saving recovery keys to databases. Also there is not any group policy defined for it.
    I you want an option to save recovery keys in a database rather than the AD, I would recommend to use MBAM (Microsoft Bitlocker Administration and Monitoring).
    Gaurav Ranjan

  • Text edges are ridged and not smooth

    I have FCE and I used livetype to add some annimated text to my video project. But when I add the text to my FCE project on playback the text edges are ridged and not smooth. How can I correct this. F.Y.I. my video projects are in HD, not sure if that would make a difference but just wanted to provide the info.
    Here is a link to the what i mean: http://www.youtube.com/watch?v=WMDLPLQdOgE
    If you watch the video in HD and about 30 secs into the clip when its just the text on the screen you can see exactly what i mean

    1. Set your LiveType project properties to match your Final Cut Sequence settings.
    In the Project Properties window you can also set the render quality. Make sure it is set to "Normal".
    2. When you add the LiveType object to your FCE timeline, it will need to be rendered. This is indicated by the colored stripe above the clip on the timeline.
    3. The Canvas always shows a low-res proxy, to better enable real time playback. Final Cut Pro will let you connect a calibrated broadcast quality monitor or at the very least, an excellent TV. This is the only way to see what you really have. I don't use FCE, so I don't know if it has this capability.

  • Iphone, Exchange Server and NOT sending "Read Mail" receipts

    I have a 3G Iphone that syncs with my office Exchange Server. I do NOT want people to see when I read or delete their emails and have my Outlook account set up that way from my desktop, however, they still get sent out from my Iphone. I haven't found a way to change this on the phone - has anyone else?
    I've seen a few older posts about this subject, but I've not been able to find anything lately that deals with my question. Thanks in advance!

    I have a 3G Iphone that syncs with my office Exchange Server. I do NOT want people to see when I read or delete their emails and have my Outlook account set up that way from my desktop, however, they still get sent out from my Iphone. I haven't found a way to change this on the phone - has anyone else?
    I've seen a few older posts about this subject, but I've not been able to find anything lately that deals with my question. Thanks in advance!

  • How to make upgrade from application server and not from central instance?

    Hello SAP Gurus!
    I have SAP ECC release 6.0, and I´m gonna make upgrade to enhancement package 6.06, do you know if Can I make upgrade from application server, but not from central instance?
    Thanks.

    Hi Victor,
    Upgrade process has to execute from the server where message server is running.
    So I guess it is not possible to initiate the SAP upgrade  from application server.
    Regards,
    Deepak Kori

  • Applet works in Windows Server and not in Unix server

    My friends,
    I have a signed applet working fine in a windows server and a client with win98. When a put this applet in a AIX/Unix server in same win98 client did not work.
    The applet call a program in the client by Runtime.exec and a give "error=0".
    Someone can help me ?

    Show the code with the runtimeexec line.
    Windows file system is different than UNix.
    Windows eg. Runtime.exec (c:/fileToRun.exe)
    *ix eg.          Runtime.exec (fileToRun)                                                                                                                                                                                                                                                                                                                                                       

  • Events working on one server and not the other

    We have a development and a production server for LC. I have events working on the development server that accept parameters.
    The services were deployed to the production server and the following error occured:
    2010-05-04 09:14:04,203 ERROR [STDERR] May 4, 2010 9:14:04 AM com.adobe.idp.scheduler.callback.ServiceCallbackHandler execute
    SEVERE: Exception thrown while calling back a DSC componentINVALID_CHARACTER_ERR: An invalid or illegal XML character is specified.
    2010-05-04 09:14:04,203 INFO  [org.quartz.core.JobRunShell] Job Asynchronous.SWR.RAAC.RequestSendEmail:12729788401870.18563775243350922 threw a JobExecutionException:
    org.quartz.JobExecutionException: java.lang.Exception: org.w3c.dom.DOMException: INVALID_CHARACTER_ERR: An invalid or illegal XML character is specified.
    [See nested exception: java.lang.Exception: org.w3c.dom.DOMException: INVALID_CHARACTER_ERR: An invalid or illegal XML character is specified. ]
        at com.adobe.idp.scheduler.callback.ServiceCallbackHandler.execute(ServiceCallbackHandler.ja va:102)
        at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
        at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529)
    Caused by: java.lang.Exception: org.w3c.dom.DOMException: INVALID_CHARACTER_ERR: An invalid or illegal XML character is specified.
        at com.adobe.idp.scheduler.callback.ServiceCallbackHandler.execute(ServiceCallbackHandler.ja va:101)
        ... 2 more
    Caused by: org.w3c.dom.DOMException: INVALID_CHARACTER_ERR: An invalid or illegal XML character is specified.
        at org.apache.xerces.dom.CoreDocumentImpl.createElement(Unknown Source)
        at com.adobe.idp.event.xml.XMLGenerator.createElement(XMLGenerator.java:500)
        at com.adobe.idp.event.xml.XMLGenerator.createEventDataDocument(XMLGenerator.java:293)
        at com.adobe.idp.event.content.EventContent.createEventDataXML(EventContent.java:173)
    I took the xml from the production service and ran it through the development server, it worked fine.
    Any idea as to where to start the troubleshooting?
    Cheers,

    It would seem that when the LCA we created to be pushed to production, the event template XSD did not get rolled up. So when the LCA was deployed, there was no definition for the event.
    What would cause this? Do you have to select another option when creating the LCA? Do you have to re-define the template after the LCA is deployed?
    Further information would be greatly appreciated.

  • Uploaded Bootstrap based site onto BC and not working correctly using IE8

    Having a problem with a Bootstrap based site that I've uploaded to a BC test site. Seems OK when viewed by everything except IE8. I have all the usual IE8 workarounds in and these work correctly on my usual external server and local host but not on BC test site . Will this resolve itself  when the site goes live ?

    Version 2 is fine to work with, it's a well designed structure. Version 3 uses some new CSS (some style name changes and new styles replacing others). The IE8 issue could be related to a new base styles. Before you do anything check/compare the paths or the CSS and JS between versions. 
    Maybe test Bootstrap 3 without any javascript, and just a very basic layout of a header, a few columns and a footer. If the IE8 issue persists, try removing CSS style tags until it breaks or resolves. Of course it may break first, so create a custom CSS file and copy the styles you want to test into that, then you can look at editing the custom copy until it resolves or breaks (don't edit the original Bootstrap CSS file as you custom CSS can override it providing you place it in the page header after the main CSS). There's a good chance you'll find the problem.
    Also see:
    http://getbootstrap.com/getting-started/#migration
    Message was edited by: Simon Darby

  • When using ctrl C in Firefox 3.6, html code accompanies the copy. How do I just copy and paste text (say to Word) and not the html?

    html accompanies text, and is embedded in microsoft Word

    Thank you so much.  I read through the entire article as well as some of its adjuncts; it was very helpful.  I believe I didn't know that was what I was looking for before you answered me.
    However, when I FIRST set up this computer (while still at the Apple store, with their guidance) they had me set up what I now believe was the administrator account.  I wish I knew for sure!
    They told me that (whatever it was) was unchangeable, and that if I forgot the password, I was doomed.
    Is there something at a yet-more-basic (underlying) level than the administrator account?
    This "memory" is what haunts me and makes me fearful of logging clear out; I never have done so.  No one else uses this computer.  But I have to log out to use the Test account (that I just created).  I DO know the password for the administrator account and the test account, as I changed them and tested them by unclicking the lock (and then reclosing it when I was.
    If I still sound confused, I am  ~  woefully.  Such a basic should not be unknown to me......
    Thank you so much for replying.  I hope you see this, and will do so one more time.
    Respectfully,
    kemandpopka

  • Export html on muse and not work when put on a server

    I created my portfolio website on Muse and exported as html. All is well when I view pages from the files I exported. When I uploaded it to a server my college provides, it shows up with this error message "Some files on the server may be missing or incorrect. Clear browser cache and try again. If the problem persists please contact website author." And all my design and pictures are either not there or all messed up. Help please!

    Have you verified that your css folder uploaded?

  • Post PDF to the SAP server and ftp it

    I got requirements regarding:  (Based on SAP Script)
    1) Convert OTF to PDF file
    2) Post this PDF file into the SAP Server
    3) FTP it to another server
    Is there anyone provide me an example source code of the step 2 and 3?

    Hi,
    Try this Funciton Module <b>/SAPDMC/LSM_F4_FRONTEND_FILE</b>,
    also Please try this Function Module, <b>C13Z_UPLOAD</b>. Might be helpful. Feel free to revert back.
    Here is a sample program.
    report zrich_0002 .
    parameters: source type localfile,
                destin type localfile.
    at selection-screen on value-request for source.
      call function 'KD_GET_FILENAME_ON_F4'
           exporting
                static    = 'X'
           changing
                file_name = source.
    at selection-screen on value-request for destin.
      call function 'KD_GET_FILENAME_ON_F4'
           exporting
                static    = 'X'
           changing
                file_name = destin.
    start-of-selection.
      data: xsource type string.
      data: xdestin type string.
      xsource = source.
      xdestin = destin.
      call method cl_gui_frontend_services=>file_copy
        exporting
          source             = xsource
          destination        = xdestin
       OVERWRITE          = SPACE
        exceptions
          cntl_error         = 1
          error_no_gui       = 2
          wrong_parameter    = 3
          disk_full          = 4
          access_denied      = 5
          file_not_found     = 6
          destination_exists = 7
          unknown_error      = 8
          path_not_found     = 9
          disk_write_protect = 10
          drive_not_ready    = 11
          others             = 12.
    Feel free to revert back.
    --Ragu

  • Text sending multiple times and not receiving all text on verizon messages website

    Hello,
    I've been using the Verizon Messages app since it was pretty much released. Overall it's worked well, however yesterday for some reason it started sending multiples of my same text to the recipient every 5-10 minutes. It continued for those persons dozens of times with the last text I would send. It didn't matter if I was sending it from my phone's (Moto Droid RAZR Maxx) verizon messaging app or the verizon messaging website. I signed in and out of the verizon messaging website but that didn't change anything. I then restarted my phone and it stopped sending multiples.
    However since that time, I now am not getting text on the verizon messaging website from anybody. I receive them on my phone's app, but not on the website. Have tried different browsers, different computers, logging off and on, but it's not reflecting the text I've received. My phone's app is getting 100% of the text as far as I'm aware.
    Anything to try on this matter would be great.
    Thanks

        Hi calhob,
    My apologies for the issues that are occuring with your VZW Messages application. Are you opening all of the messages directly on your device? If you do not open one of the messages, does this message show online? Are you able to send messaging from the computer based website? Please keep us posted, thanks!
    MatthewS_VZW
    Follow us on Twitter @VZWSUPPORT

  • Trying to install VM Server and not getting the CD found screen to display

    Trying to install Oracle VM Server from a CDROM:
    1.     Insert the Oracle VM Server CDROM into your CDROM drive.
    2.     Boot the computer with the Oracle VM Server CDROM.
    3.     The Oracle VM Server screen is displayed.
    All that went fine but not getting the CD found screen to display. Instead it says the device wasn't found and shows a list of drivers, none of which seem to match the CD drive. Anyone have any ideas? There is an option to point it to a driver disk, not sure if I need to get the driver from somewhere and do that or not?
    machine is Dell Optiplex 760
    CD RW\DVD RW drive

    Try changing the SATA mode in the BIOS to AHCI.

  • Published to folder iWeb site always using Times New Roman for every piece of text in published site and not showing the original text style used when building the site in iWeb.

    Dear All
    Hello from rainy, windy and cold North East England! I need to ask for your help as I'm new to iMac and new to iWeb and it's frustrating the life out of me!
    I'm just beginning to build a website for my business. Previously, I used Frontpage, but it's been that long since I used it - I've forgotten half of it and so, I'm using iWeb instead as it's silly to use an iMac for business but a PC laptop for the website design.
    I've got the background image I want on the homepage (beautiful image of a rain forest - even if I do say so myself!) and I'm trying to enter a text box at the lower half of the screen, in the centre of the page saying 'click to enter'. I type in the text, I edit it so as to change it to the font style of my company (Gill sans MT) and then I publish the site to a folder so that I can see what it would look like when viewed via the internet. When I do this - the font changes size to a bog standard size of 'so small you need a magnifying glass to read it', it changes colour from black to purple (which looks disgusting) and it changes font style from Gill Sans MT to Times New Roman.
    It doesn't matter if I delete the entire site and start again or delete the text box, and insert a new one. I've googled this subject until I'm blue in the face and I can't find an answer - can anyone suggest anything that will help?
    Many thanks for your help,
    Best wishes,
    Sean.

    Try the following:
    delete the iWeb preference files, com.apple.iWeb.plist and com.apple.iWeb.plist.lockfile, that resides in your Home() /Library/Preferences folder.
    go to your Home()/Library/Caches/com.apple.iWeb folder and delete its contents.
    Click to view full size
    launch iWeb and try again.
    NOTE: If you don't use  Web Safe Fonts any computer that does not have that font installed  will substitute another font for it and change the look and feel of the web page.
    So it's safest to use one of those web safe fonts.
    OT

  • 4s  has 5000 photos on it computer crashed so i have a new one how do i put all photos onto computer and not just camera roll ones

    My computer crashed and my i phone 4s has over 5000 photos on it ,ive reinstalled itunes but i want to know how to get all photos from phone to computer ,im to scared to snc it as i dont know if i will loose all the photos ,i can get camera roll by basic computer hook up can some one tell me how to do this without loosing my photos thankyou to anyone who can help

    to copy photos from your iPhone to your computer you can either use photo stream via icloud and the icloud control panel for windows see http://www.apple.com/icloud/setup/pc.html  OR plug your phone in and open up  your "my computer" and navigate to your iPhone it should provide you with a way to view the photos just like any digital camera.

Maybe you are looking for

  • HP7960 black and white prints half purple

    We use the HP7960 mostly to print copies of black and white photographs.  The copies start out fine, but change to purple about midway through the page.  I have set the color to Grayscale but it doesn't seem to make any difference.  It is very import

  • CF card reader for photo impport does not show on LR3

    Firsst I'm a newbie to Apple and LR3 and using Scott Kelby's LR3 book to start. Incredible as it may be I'm stuck beyond Step 2 (the very beginning of the book) in trying to import photos, first form a DVD and also from a CF card reader. The error me

  • How to make a copy of photos taken on iPad camera?

    I've only just got an iPad so forgive me if this is really basic but I want to make a copy of a photo I have taken with the camera on the iPad so I can edit one but still have the original. I've tried copy image but it doesn't seem to do anything, I'

  • How to open the CD/DVD tray?

    I tried with ctrl+eject keys, aslo cmd+eject, fn+eject, only eject, but nothing happens. How do you open the CD/DVD tray to incert a CD or DVD?

  • HT201328 Does it matter what type of sim is in the phone when I do the restore?

    I received confirmation from AT&T that my phone was eligible but I want to use it on T Mobile. If I restore the phone with the AT&T sim inserted does it make any difference?