r/unity • u/[deleted] • Aug 09 '22
Coding Help How to send Encode URL data in Unity?
My problem is that when the REST API call is executed, the character %e2%80%8b or %E2%80%8b is added to the URL after the pageTitle variable. I was wondering how I can remove these characters from the URL when it is being sent.
Here is my code:
public static string pageTitle = "Cat"; My code inside the method:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://en.wikipedia.org/api/rest_v1/page/summary/" + UnityWebRequest.EscapeURL(pageTitle) + "?redirect=true"); The URL I get looks like this: https://en.wikipedia.org/api/rest_v1/page/summary/Cat%e2%80%8b?redirect=true Or https://en.wikipedia.org/api/rest_v1/page/summary/Cat%E2%80%8b?redirect=true
I want the URL to look like this: https://en.wikipedia.org/api/rest_v1/page/summary/Cat?redirect=true
2
2
u/TVOHM Aug 09 '22
I think the other comments are correct on your url issue.
I just wanted to add, unless you have a specific reason, to consider using UnityWebRequest.Get instead of HttpWebRequest.
Some Unity build targets (notably WebGL) only support UnityWebRequest.
2
u/raw65 Aug 09 '22
It looks like %E2%80%8b is a UTF-8 "zero width space" character. My guess is that you pasted "Cat" from another application and inadvertently got an extra (invisible) UTF character.
Try deleting "Cat" and retyping it carefully. Or (if you are using Windows) cut it, paste it into Notepad (NOT Notepad++), then cut it and paste it back into your program.