Send string containing html in url without removing special chars












-1















I'm trying to send a message which is a string containing an icon which is a html element but when i pass it in my web service url it removes all special chars . Is there a way to leave it as a string without removing these special chars ?



the string that i want to pass is



      var body= "hello <img src="/assets/smile.png">";


the web service url is :



  return this.http.get('  http://localhost:44435/Projet/AddMsessage?body=' +body+ '&idSender=' + idSender + '&idDiscussion=' + idDiscussion);


but the probleme that when i execute the webservice it changes into this :



http://localhost:44435/Projet/AddMsessage?body=halo%20%3Cimg%20src%3D%22%2Fassets%2Fsmile.png%22%3E%20&idSender=1&idDiscussion=1


it removes the < , / , " ,> chars










share|improve this question























  • The encoded URL looks OK to me. You could decode it at the receiving end. By the way, the inner quotes in body should probably be single quotes (or the double quotes should be escaped).

    – ConnorsFan
    Jan 1 at 1:41


















-1















I'm trying to send a message which is a string containing an icon which is a html element but when i pass it in my web service url it removes all special chars . Is there a way to leave it as a string without removing these special chars ?



the string that i want to pass is



      var body= "hello <img src="/assets/smile.png">";


the web service url is :



  return this.http.get('  http://localhost:44435/Projet/AddMsessage?body=' +body+ '&idSender=' + idSender + '&idDiscussion=' + idDiscussion);


but the probleme that when i execute the webservice it changes into this :



http://localhost:44435/Projet/AddMsessage?body=halo%20%3Cimg%20src%3D%22%2Fassets%2Fsmile.png%22%3E%20&idSender=1&idDiscussion=1


it removes the < , / , " ,> chars










share|improve this question























  • The encoded URL looks OK to me. You could decode it at the receiving end. By the way, the inner quotes in body should probably be single quotes (or the double quotes should be escaped).

    – ConnorsFan
    Jan 1 at 1:41
















-1












-1








-1








I'm trying to send a message which is a string containing an icon which is a html element but when i pass it in my web service url it removes all special chars . Is there a way to leave it as a string without removing these special chars ?



the string that i want to pass is



      var body= "hello <img src="/assets/smile.png">";


the web service url is :



  return this.http.get('  http://localhost:44435/Projet/AddMsessage?body=' +body+ '&idSender=' + idSender + '&idDiscussion=' + idDiscussion);


but the probleme that when i execute the webservice it changes into this :



http://localhost:44435/Projet/AddMsessage?body=halo%20%3Cimg%20src%3D%22%2Fassets%2Fsmile.png%22%3E%20&idSender=1&idDiscussion=1


it removes the < , / , " ,> chars










share|improve this question














I'm trying to send a message which is a string containing an icon which is a html element but when i pass it in my web service url it removes all special chars . Is there a way to leave it as a string without removing these special chars ?



the string that i want to pass is



      var body= "hello <img src="/assets/smile.png">";


the web service url is :



  return this.http.get('  http://localhost:44435/Projet/AddMsessage?body=' +body+ '&idSender=' + idSender + '&idDiscussion=' + idDiscussion);


but the probleme that when i execute the webservice it changes into this :



http://localhost:44435/Projet/AddMsessage?body=halo%20%3Cimg%20src%3D%22%2Fassets%2Fsmile.png%22%3E%20&idSender=1&idDiscussion=1


it removes the < , / , " ,> chars







angular






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 1 at 1:26









AOUADI SlimAOUADI Slim

7311




7311













  • The encoded URL looks OK to me. You could decode it at the receiving end. By the way, the inner quotes in body should probably be single quotes (or the double quotes should be escaped).

    – ConnorsFan
    Jan 1 at 1:41





















  • The encoded URL looks OK to me. You could decode it at the receiving end. By the way, the inner quotes in body should probably be single quotes (or the double quotes should be escaped).

    – ConnorsFan
    Jan 1 at 1:41



















The encoded URL looks OK to me. You could decode it at the receiving end. By the way, the inner quotes in body should probably be single quotes (or the double quotes should be escaped).

– ConnorsFan
Jan 1 at 1:41







The encoded URL looks OK to me. You could decode it at the receiving end. By the way, the inner quotes in body should probably be single quotes (or the double quotes should be escaped).

– ConnorsFan
Jan 1 at 1:41














1 Answer
1






active

oldest

votes


















0














You're supposed to use HttpClient#get's second parameter to pass URL parameters. See the official documentation for more information.



Your code becomes:



return this.http.get('http://localhost:44435/Projet/AddMsessage', {
params: new HttpParams()
.set('body', body)
.set('idSender', idSender)
.set('idDiscussion', idDiscussion)
});


If you don't, if your parameters' values contain characters such as ? or &, they'll screw up your URL as Angular has no way of knowing where each parameter "stops".



However, it's perfectly normal for special characters to be url encoded. < becomes %3C and so on.






share|improve this answer


























  • Jeto i just tried your answer but still the same probleme it didn't work :/

    – AOUADI Slim
    Jan 1 at 1:35











  • @AOUADISlim What do you mean, what exactly is happening? Can you paste the final URL that's being requested (from your browser's console)?

    – Jeto
    Jan 1 at 1:36











  • Also, "AddMsessage" is suspicious, shouldn't it be "AddMessage"?

    – Jeto
    Jan 1 at 1:38






  • 1





    It's normal as my answer states, and everyone else did tell you as well (@Soumare, @ConnorsFan). Special characters are supposed to be URL-encoded, they'll be decoded automatically when reaching the API endpoint.

    – Jeto
    Jan 1 at 1:54








  • 1





    There is no reason to.

    – Jeto
    Jan 1 at 1:55











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992503%2fsend-string-containing-html-in-url-without-removing-special-chars%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You're supposed to use HttpClient#get's second parameter to pass URL parameters. See the official documentation for more information.



Your code becomes:



return this.http.get('http://localhost:44435/Projet/AddMsessage', {
params: new HttpParams()
.set('body', body)
.set('idSender', idSender)
.set('idDiscussion', idDiscussion)
});


If you don't, if your parameters' values contain characters such as ? or &, they'll screw up your URL as Angular has no way of knowing where each parameter "stops".



However, it's perfectly normal for special characters to be url encoded. < becomes %3C and so on.






share|improve this answer


























  • Jeto i just tried your answer but still the same probleme it didn't work :/

    – AOUADI Slim
    Jan 1 at 1:35











  • @AOUADISlim What do you mean, what exactly is happening? Can you paste the final URL that's being requested (from your browser's console)?

    – Jeto
    Jan 1 at 1:36











  • Also, "AddMsessage" is suspicious, shouldn't it be "AddMessage"?

    – Jeto
    Jan 1 at 1:38






  • 1





    It's normal as my answer states, and everyone else did tell you as well (@Soumare, @ConnorsFan). Special characters are supposed to be URL-encoded, they'll be decoded automatically when reaching the API endpoint.

    – Jeto
    Jan 1 at 1:54








  • 1





    There is no reason to.

    – Jeto
    Jan 1 at 1:55
















0














You're supposed to use HttpClient#get's second parameter to pass URL parameters. See the official documentation for more information.



Your code becomes:



return this.http.get('http://localhost:44435/Projet/AddMsessage', {
params: new HttpParams()
.set('body', body)
.set('idSender', idSender)
.set('idDiscussion', idDiscussion)
});


If you don't, if your parameters' values contain characters such as ? or &, they'll screw up your URL as Angular has no way of knowing where each parameter "stops".



However, it's perfectly normal for special characters to be url encoded. < becomes %3C and so on.






share|improve this answer


























  • Jeto i just tried your answer but still the same probleme it didn't work :/

    – AOUADI Slim
    Jan 1 at 1:35











  • @AOUADISlim What do you mean, what exactly is happening? Can you paste the final URL that's being requested (from your browser's console)?

    – Jeto
    Jan 1 at 1:36











  • Also, "AddMsessage" is suspicious, shouldn't it be "AddMessage"?

    – Jeto
    Jan 1 at 1:38






  • 1





    It's normal as my answer states, and everyone else did tell you as well (@Soumare, @ConnorsFan). Special characters are supposed to be URL-encoded, they'll be decoded automatically when reaching the API endpoint.

    – Jeto
    Jan 1 at 1:54








  • 1





    There is no reason to.

    – Jeto
    Jan 1 at 1:55














0












0








0







You're supposed to use HttpClient#get's second parameter to pass URL parameters. See the official documentation for more information.



Your code becomes:



return this.http.get('http://localhost:44435/Projet/AddMsessage', {
params: new HttpParams()
.set('body', body)
.set('idSender', idSender)
.set('idDiscussion', idDiscussion)
});


If you don't, if your parameters' values contain characters such as ? or &, they'll screw up your URL as Angular has no way of knowing where each parameter "stops".



However, it's perfectly normal for special characters to be url encoded. < becomes %3C and so on.






share|improve this answer















You're supposed to use HttpClient#get's second parameter to pass URL parameters. See the official documentation for more information.



Your code becomes:



return this.http.get('http://localhost:44435/Projet/AddMsessage', {
params: new HttpParams()
.set('body', body)
.set('idSender', idSender)
.set('idDiscussion', idDiscussion)
});


If you don't, if your parameters' values contain characters such as ? or &, they'll screw up your URL as Angular has no way of knowing where each parameter "stops".



However, it's perfectly normal for special characters to be url encoded. < becomes %3C and so on.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 1 at 2:00

























answered Jan 1 at 1:32









JetoJeto

5,72021119




5,72021119













  • Jeto i just tried your answer but still the same probleme it didn't work :/

    – AOUADI Slim
    Jan 1 at 1:35











  • @AOUADISlim What do you mean, what exactly is happening? Can you paste the final URL that's being requested (from your browser's console)?

    – Jeto
    Jan 1 at 1:36











  • Also, "AddMsessage" is suspicious, shouldn't it be "AddMessage"?

    – Jeto
    Jan 1 at 1:38






  • 1





    It's normal as my answer states, and everyone else did tell you as well (@Soumare, @ConnorsFan). Special characters are supposed to be URL-encoded, they'll be decoded automatically when reaching the API endpoint.

    – Jeto
    Jan 1 at 1:54








  • 1





    There is no reason to.

    – Jeto
    Jan 1 at 1:55



















  • Jeto i just tried your answer but still the same probleme it didn't work :/

    – AOUADI Slim
    Jan 1 at 1:35











  • @AOUADISlim What do you mean, what exactly is happening? Can you paste the final URL that's being requested (from your browser's console)?

    – Jeto
    Jan 1 at 1:36











  • Also, "AddMsessage" is suspicious, shouldn't it be "AddMessage"?

    – Jeto
    Jan 1 at 1:38






  • 1





    It's normal as my answer states, and everyone else did tell you as well (@Soumare, @ConnorsFan). Special characters are supposed to be URL-encoded, they'll be decoded automatically when reaching the API endpoint.

    – Jeto
    Jan 1 at 1:54








  • 1





    There is no reason to.

    – Jeto
    Jan 1 at 1:55

















Jeto i just tried your answer but still the same probleme it didn't work :/

– AOUADI Slim
Jan 1 at 1:35





Jeto i just tried your answer but still the same probleme it didn't work :/

– AOUADI Slim
Jan 1 at 1:35













@AOUADISlim What do you mean, what exactly is happening? Can you paste the final URL that's being requested (from your browser's console)?

– Jeto
Jan 1 at 1:36





@AOUADISlim What do you mean, what exactly is happening? Can you paste the final URL that's being requested (from your browser's console)?

– Jeto
Jan 1 at 1:36













Also, "AddMsessage" is suspicious, shouldn't it be "AddMessage"?

– Jeto
Jan 1 at 1:38





Also, "AddMsessage" is suspicious, shouldn't it be "AddMessage"?

– Jeto
Jan 1 at 1:38




1




1





It's normal as my answer states, and everyone else did tell you as well (@Soumare, @ConnorsFan). Special characters are supposed to be URL-encoded, they'll be decoded automatically when reaching the API endpoint.

– Jeto
Jan 1 at 1:54







It's normal as my answer states, and everyone else did tell you as well (@Soumare, @ConnorsFan). Special characters are supposed to be URL-encoded, they'll be decoded automatically when reaching the API endpoint.

– Jeto
Jan 1 at 1:54






1




1





There is no reason to.

– Jeto
Jan 1 at 1:55





There is no reason to.

– Jeto
Jan 1 at 1:55




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992503%2fsend-string-containing-html-in-url-without-removing-special-chars%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas