I have issue with passing data from angular to webapi. I need to translate some phrases from my DB and everything works until my phrase looks like this:
"day w/o break"
Because in this situation my request to webapi looks like:
https://localhost:44973/api/translation/getResstring/day%20w/o%20break
And that character / destroying the request. How to pass it to WebApi correctly? I did it in hurry yesterday do encode on Angular side and decode on Web Api side but it not works, so i decided to revert it.
Yesterday attempt, angular app:
[...]
public getResstringByPhrase(
source: string
): Observable<string> {
const result = this.http.get(this.url + "getResstring/" + source, { responseType: 'text' })
return result
}
[...]
.net Core web api:
[HttpGet("{*phrase}")]
[Route("getResstring/{phrase}")]
public IActionResult Get(string phrase)
{
var resstring = _translationRepository.GetResstringByPhrase(phrase);
return new OkObjectResult(resstring);
}
Startup.cs (only Configure):
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
} }
But even with this attempt, it doesn't work with phrases with "/" symbol
#UPDATE
Conflicting action:
[HttpGet("{languageCharset}/{resstring}")]
[Route("{languageCharset}/{resstring}")]
public IActionResult Get(string resstring, LanguageCharset languageCharset)
{
var translate = _translationRepository.GetTranslatedByResstring(resstring, languageCharset);
return new OkObjectResult(translate);
}
#UPDATE 2:
I made it, now "/" works, but i have problems with "+". Code
Webapi:
[HttpGet("{phrase}")]
[Route("getResstring/{phrase}")]
public IActionResult Get(string phrase)
{
phrase = HttpUtility.UrlDecode(phrase);
var resstring = _translationRepository.GetResstringByPhrase(phrase);
return new OkObjectResult(resstring);
}
Angular app:
if( translatedElements[index].getIsTranslated() === false ) {
this.getResstringByPhrase(encodeURIComponent(translatedElements[index].getValue())).subscribe(async res => {
const translatedLabel = await this.GetTranslatedByResstring(res, 1045).toPromise()
if (translatedLabel.getPhrase() !== '') {
translatedElements[index].setValue(translatedLabel.getPhrase())
}
})
}
And now the error is (only appears when phrase have "+" inside):
HTTP Error 404.11 - Not Found
The request filtering module is configured to reject the rejection of the cancellation of an alternate double solution. (sorry for translation from my language)