remote server not worked at navodaya sammithi - javascript

Unable to connect to the remote server at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) at System.Net.HttpWebRequest.GetRequestStream() at ECSAuaInterfaceExApi.ECSAuaInterfaceExApiHelper.PHAvIPcIIPLvUh8K75j(Object ) at ECSAuaInterfaceExApi.ECSAuaInterfaceExApiHelper.aw8D71cfy(String ) at ECSAuaInterfaceExApi.ECSAuaInterfaceExApiHelper.TN4fEStTS[PQS8ErhEaTOwOar4xQ](String , Object ) at ECSAuaInterfaceExApi.ECSAuaInterfaceExApiHelper.GenerateOtp(String requestId, String uid, String txnId, String consent, Boolean sendSMS, Boolean sendEmail, String udf1, String udf2, String udf3, String udf4, String udf5, String udf6, String udf7, String udf8, String udf9, String udf10) at NVSMVCApp.Controllers.IndexController.Registration(pRegistrationDetailPhase1and2 cls, HttpPostedFileBase fileCertificate, FormCollection collection) in D:\Sandeep\NVSMVCApplatest\NVSMVCApp\Controllers\IndexController.cs:line 283
not worked
did not work navodaya

This title does not meet our quality standards. Please make sure that it clearly summarizes your problem and uses proper grammar. You can put details in the body of your question.

Related

Typescript JSON.parse turkish character conversion problem [duplicate]

This question already has answers here:
Using Javascript's atob to decode base64 doesn't properly decode utf-8 strings
(12 answers)
Closed last month.
I have a code that decodes JWT tokens, splits the string part that contains claims and converts that info into a JSON object.
return JSON.parse(atob(token.split('.')[1])) as LoggedInUser;
It works but when it comes to user's name, since it has some turkish characters, I get a string with non-readable characters. User's name is "Uğur Gül" in the picture below.
I think I should somehow parse with utf-8 formatting but can't find how to that. I'm working with angular framework. How can I fix this issue?
Edit: Here is a decoded version of my mock-data token on jwt.io. I'm trying to get the payload from token like the way jwt.io creates an JSON object, and I'm assigning needed values to related fields to an instance of LoggedInUser class.
One way is to escape and unescape the name on the backend/frontend. I don't know how your app works.
We use escape and Uğur Gül will converted to U%u011Fur%20G%FCl. Set this to GivenUserName, create the token and send it to the frontend. Frontend decodes it, gave the name and call unescape. So you have the correct name again.
Sample:
data = '{"UserId":"2","UserGivenName":"U%u011Fur%20G%FCl","http://schemas.microsoft.com/ws/2008/06/identity/claims/role":"2","exp":1672046375,"iss":"https://localhost:7013/","aud":"https://localhost:7013/"}'
constructor() {
console.log((escape("Uğur Gül")));
console.log(unescape(escape("Uğur Gül")))
this.token = (btoa(this.data))
const jsonData = JSON.parse(atob(this.token));
console.log(unescape(jsonData.UserGivenName));
}
Important
escape and unescape are marked as deprecated. You can use encodeURI and decodeURI instead:
console.log(encodeURI('Uğur Gül'));
console.log(decodeURI(encodeURI('Uğur Gül')));
Here is a Stackblitz to play.

Decoding Base64 String in Java

I'm using Java and I have a Base64 encoded string that I wish to decode and then do some operations to transform.
The correct decoded value is obtained in JavaScript through function atob(), but in java, using Base64.decodeBase64() I cannot get an equal value.
Example:
For:
String str = "AAAAAAAAAAAAAAAAAAAAAMaR+ySCU0Yzq+AV9pNCCOI="
With JavaScript atob(str) I get ->
"Æ‘û$‚SF3«àö“Bâ"
With Java new String(Base64.decodeBase64(str)) I get ->
"Æ?û$?SF3«à§ö?â"
Another way I could fixed the issue is to run JavaScript in Java with a Nashorn engine, but I'm getting an error near the "$" symbol.
Current Code:
ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
String script2 = "function decoMemo(memoStr){ print(atob(memoStr).split('')" +
".map((aChar) => `0${aChar.charCodeAt(0).toString(16)}`" +
".slice(-2)).join('').toUpperCase());}";
try {
engine.eval(script2);
Invocable inv = (Invocable) engine;
String returnValue = (String)inv.invokeFunction("decoMemo", memoTest );
System.out.print("\n result: " + returnValue);
} catch (ScriptException | NoSuchMethodException e1) {
e1.printStackTrace();
Any help would be appreciated. I search a lot of places but can't find the correct answer.
btoa is broken and shouldn't be used.
The problem is, bytes aren't characters. Base64 encoding does only one thing. It converts bytes to a stream of characters that survive just about any text-based transport mechanism. And Base64 decoding does that one thing in reverse, it converts such characters into bytes.
And the confusion is, you're printing those bytes as if they are characters. They are not.
You end up with the exact same bytes, but javascript and java disagree on how you're supposed to turn that into an ersatz string because you're trying to print it to a console. That's a mistake - bytes aren't characters. Thus, some sort of charset encoding is being used, and you don't want any of this, because these characters clearly aren't intended to be printed like that.
Javascript sort of half-equates characters and bytes and will freely convert one to the other, picking some random encoding. Oof. Javascript sucks in this regard, it is what it is. The MDN docs on btoa explains why you shouldn't use it. You're running into that problem.
Not entirely sure how you fix it in javascript - but perhaps you don't need it. Java is decoding the bytes perfectly well, as is javascript, but javascript then turns those bytes into characters into some silly fashion and that's causing the problem.
What you have there is not a text string at all. The giveaway is the AA's at the beginning. Those map to a number of zero bytes. That doesn't translate to meaningful text in any standard character set.
So what you have there is most likely binary data. Converting it to a string is not going to give you meaningful text.
Now to explain the difference you are seeing between Java and Javascript. It looks to me as if both Java and Javascript are making a "best effort" attempt to convert the binary data as if is was encoded in ISO-8859-1 (aka ISO LATIN-1).
The problem is some of the bytes codes are mapping to unassigned codes.
In the Java case those unassigned codes are being mapped to ?, either when the string is created or when it is being output.
In the Javascript case, either the unassigned codes are not included in the string, or them are being removed when you attempt to display them.
For the record, this is how an online base64 decoder the above for me:
����������������Æû$SF3«àöBâ
The unassigned codes are 0x91 0x82 and 0x93. 0x15 and 0x0B are non-printing control codes.
But the bottom line is that you should not be converting this data into a string in either Java or in Javascript. It should be treated as binary; i.e. an array of byte values.
byte[] data = Base64.getDecoder().decode(str);

Which string encoding is this?

On one of my webhooks, I am receiving the following string
9\x09?\x09\x02\x09&\x09#
This was supposed to be the text in regional language. For English, the content seems fine. But for vernacular strings, the service provider is sending this. Consider that I am using Javascript, how do I decode this string?
This is how the webhook is being called :
/api/test?content=9\x09?\x09\x02\x09&\x09#&timestamp=20210120145223
It's ASCII. All occurrences of the four characters \xST are converted to 1 character, whose ASCII code is ST (in hexadecimal), where S and T are any of 0123456789abcdefABCDEF.

How to encode and decode query string from javascript to servletpage using java?

How to encode and decode query string from javascript to servletpage
Javascript
var page=http://localhost/jsp/index.jsp?pname=jack & sparrow&price=$20&rate=10 - 20%
$('#listContent').load(page);
I got 404 error
var page=http://localhost/jsp/index.jsp?pname=titanic&price=10&rate=12
$('#listContent').load(page);
this one working fine
how to pass if query string contain space and special symbols
how to encode it and how to pass this query string
if it is encoded how to decode in servlet page
My expected output as
String pname=request.getParameter("pname")
String price=request.getParameter("price")
String rate=request.getParameter("rate")
pname=jack & sparrow
price=$20
rate=10 - 20%
On the Javascript side you have to encode it using function encodeURIComponent(yourString)
If you want to decode such string on Java side, you can do it using (for example) new java.net.URI(receivedString).getPath()

How to remove escape characters from Json string?

I have a c# method that calls another method which returns back a string that is supposed to represent JSON. However, the string has escape characters in it:
public string GetPerson()
{
string person = repo.GetPerson(); //person is "{\"name\":jack,\"age\":\"54\"...
return person;
}
If I try to do a replace, there is no change:
string person = repo.GetPerson().Replace(#"\""", ""); //person still has escape characters
When I try to view person in the text viewer when debugging, the escape characters are not there--Visual Studio rips them off. But my javascript that calls this method does see the escape characters in the ajax response.
If I try to deserialize the person string into my C# User object, it does not deserialize properly:
User user = JsonConvert.DeserializeObject<User>(person);
What are my options? How can I either strip off the escape characters from the person string, or deserialize it correctly to the User object?
If a Console.WriteLine(person) shows those backslashes and quotes around the string (not just the string and quotes inside), then there is a double serialization issue. You could try first to deserialize it to a string, then to a type, like this:
User user = JsonConvert.DeserializeObject<User>(JsonConvert.DeserializeObject<String>(person));
Also, you could try to do:
string person = repo.GetPerson().Replace(#"\""", #"""");
If you have control over the API, check for double serialization on return. ASP does a default serialization, so usually you don't have to return a string with the object pre-serialized.
For webapi, use Ok(object), for ASP MVC, use Json(object, requestBehaviour) methods.

Categories

Resources