Click here to Skip to main content
15,890,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to Pass special character in Web Api Post method?
I am save the special character like '&',''' in web api via post method.

Problem is when i am pass the special character via parameter then special character remove the web api and save the value without special character.

I am 1st create a web api then this web api call the your asp.net project. I am call the web api via Web client.
Please see the exp:
C#
string URI = ApiBaseURL + "project/Updateproject";
                        string myParameters = "ProjectId=" + projectid + "&ProjectStatusId=" + projectstatusid + "&ProjectName=" +
                            projectname + "&ProjectImage=" + fileName + "&Description=" + description + "&FloorPlan=" + floorplan +
                            "&ProjectAddress=" + address + "&ProjectCategoryId=" + projectcategoryid + "&CityId=" +
                            cityid + "&ProjectBudgetLowPrice=" + budgetlowprice + "&ProjectBudgetHighPrice=" + budgethighprice +
                            "&ProjectLogo=" + ProjectLogo + "&YoutubeLink=" + youtubelink + "&FeaturePropertyFlag=" + featuredpropertyflag
                            + "&Property=" + property + "&Video=" + videofile + "&Phone=" + phone + "&SocialContactNo=" + socialPh +
                            "&PpcContactNo=" + ppcphone + "&ThreeSixtyDegreeVideo=" + threesixtyfilelink + "&LoyaltyPoint=" + loyaltypoint
                            + "&ProjectDurationId=" + ProjectDurationId + "&latitude=" + latitude + "&longitude=" + longitude +
                            "&PhotoGallaryShrtDesc=" + PhotoGallaryShrtDesc + "&LocationShrtDesc=" + LocationShrtDesc + "&LandingViewFlag="
                            + LandingViewFlag + "&ProjectBudgetRange=" + ProjectBudgetRange + "&ProjectLinkId=" + ProjectLinkId + "&ProjectExternalLink=" + ProjectExternalLink;

                        using (WebClient wc = new WebClient())
                        {
                            wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
                            HtmlResult = wc.UploadString(URI, myParameters);
                        }


What I have tried:

How to Pass special character in Web Api Post method?
I am save the special character like '&',''' in web api via post method.

Problem is when i am pass the special character via parameter then special character remove the web api and save the value without special character.

I am 1st create a web api then this web api call the your asp.net project. I am call the web api via Web client.
Please see the exp:
C#
string URI = ApiBaseURL + "project/Updateproject";
                        string myParameters = "ProjectId=" + projectid + "&ProjectStatusId=" + projectstatusid + "&ProjectName=" +
                            projectname + "&ProjectImage=" + fileName + "&Description=" + description + "&FloorPlan=" + floorplan +
                            "&ProjectAddress=" + address + "&ProjectCategoryId=" + projectcategoryid + "&CityId=" +
                            cityid + "&ProjectBudgetLowPrice=" + budgetlowprice + "&ProjectBudgetHighPrice=" + budgethighprice +
                            "&ProjectLogo=" + ProjectLogo + "&YoutubeLink=" + youtubelink + "&FeaturePropertyFlag=" + featuredpropertyflag
                            + "&Property=" + property + "&Video=" + videofile + "&Phone=" + phone + "&SocialContactNo=" + socialPh +
                            "&PpcContactNo=" + ppcphone + "&ThreeSixtyDegreeVideo=" + threesixtyfilelink + "&LoyaltyPoint=" + loyaltypoint
                            + "&ProjectDurationId=" + ProjectDurationId + "&latitude=" + latitude + "&longitude=" + longitude +
                            "&PhotoGallaryShrtDesc=" + PhotoGallaryShrtDesc + "&LocationShrtDesc=" + LocationShrtDesc + "&LandingViewFlag="
                            + LandingViewFlag + "&ProjectBudgetRange=" + ProjectBudgetRange + "&ProjectLinkId=" + ProjectLinkId + "&ProjectExternalLink=" + ProjectExternalLink;

                        using (WebClient wc = new WebClient())
                        {
                            wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
                            HtmlResult = wc.UploadString(URI, myParameters);
                        }
Posted
Updated 16-Jul-17 22:30pm
v2

1 solution

depending of how you want to use this string, you will have to encode it for html or for url use:
C#
Server.HTMLEncode(string)

C#
Server.URLEncode(string)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900