I am trying to do a REST client using AS3, I am following this tutorial: http://help.adobe.com/en_US/as3/dev/WSb2ba3b1aad8a27b061afd5d7127074bbf44-8000.html
My code is the following:
import flash.events.Event;
import flash.events.ErrorEvent;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
var url:String = "https://localhost:8443/restcomponent/tesimalex";
var requestor:URLLoader = new URLLoader();
function restServiceCall():void
{
trace("Calling REST Service...");
//Create the HTTP request object
var request:URLRequest = new URLRequest( url );
request.method = URLRequestMethod.GET;
//Add the URL variables
// var variables:URLVariables = new URLVariables();
// variables.method = "test.echo";
// variables.api_key = "123456ABC";
// variables.message = "Able was I, ere I saw Elba.";
// request.data = variables;
//Initiate the transaction
requestor = new URLLoader();
requestor.addEventListener( Event.COMPLETE, httpRequestComplete );
requestor.addEventListener( IOErrorEvent.IO_ERROR, httpRequestError );
requestor.addEventListener( SecurityErrorEvent.SECURITY_ERROR, httpRequestError );
requestor.load( request );
}
function httpRequestComplete( event:Event ):void
{
trace( event.target.data );
}
function httpRequestError( error:ErrorEvent ):void{
trace( "An error occured: " + error.toString() );
}
The only diference between my code and the one in the tutorial is the URL variables, that I commented, and the url used.
My REST service is a simple GET, if I type the url in the browser it shows me the JSON returned.
But in my AS3, when I call the method restServiceCall() it returns the following error:
Error opening URL 'https://localhost:8443/restcomponent/tesimalex?' An
error occured: [IOErrorEvent type="ioError" bubbles=false
cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL:
https://localhost:8443/restcomponent/tesimalex?"]
Anyone knows whats wrong?
Ok... It was a security issue... I disabled SSL in my server and then my flash app managed to comunicate with my REST service.
Related
I'm trying to send an automated message to discord from my account token using the axios client, it worked on a different project of mine but it doesn't work on a brand new project for some reason. Here is the code so far:
const axios = require('axios').default;
async function Post() {
const URL = `https://discord.com/api/v9/channels/${process.env.CHANNEL}/messages`
const payload = { content: "This message has been sent using axios!" }
await axios.post(URL, payload, { headers: { 'authorization': process.env.TOKEN } })
}
Post();
This is the error I'm getting:
node:internal/errors:464
ErrorCaptureStackTrace(err);
^
TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "authorization"
at ClientRequest.setHeader (node:_http_outgoing:579:3)
at new ClientRequest (node:_http_client:256:14)
at Object.request (node:https:353:10)
at RedirectableRequest._performRequest (/home/nonce/Documents/Repositories/test/node_modules/follow-redirects/index.js:279:24)
at new RedirectableRequest (/home/nonce/Documents/Repositories/test/node_modules/follow-redirects/index.js:61:8)
at Object.request (/home/nonce/Documents/Repositories/test/node_modules/follow-redirects/index.js:482:14)
at dispatchHttpRequest (/home/nonce/Documents/Repositories/test/node_modules/axios/lib/adapters/http.js:232:25)
at new Promise (<anonymous>)
at httpAdapter (/home/nonce/Documents/Repositories/test/node_modules/axios/lib/adapters/http.js:48:10)
at dispatchRequest (/home/nonce/Documents/Repositories/test/node_modules/axios/lib/core/dispatchRequest.js:58:10) {
code: 'ERR_HTTP_INVALID_HEADER_VALUE'
}
And for the record, I'm not trying to create a spammer or anything that breaks Discord's API rules.
Here are the versions I'm using, if it helps in any way:
node: v16.13.2
npm: v8.1.2
axios: v0.25.0
Found the error, I forgot to add the dotenv package all along.
please provide any code or any example or any link.
vm.dtOptions = DTOptionsBuilder.fromSource( baseApi + '/NH/dashboard' ).withFnServerParams( serverParams );
function serverParams ( aoData ) {
aoData.push( jsonObj );
}
it gives error..
DTOptionsBuilder.fromSource(...).withFnServerParams is not a function
Hi I'm trying to send a POST call to the SparkPost API in a JavaScript web app. It works fine with curl and Postman, but as soon as I try sending from my localhost site I get a 401 Unauthorized error.
My current code looks like the below, but I've tried fetch as well with the same results.
sendEmail(subject, data) {
let textbody = "blah blah blah";
const url = "https://api.sparkpost.com/api/v1/transmissions";
const fetchbody = {
content: {
from: "sandbox#sparkpostbox.com",
subject: subject,
text: textbody
},
recipients: [{address: "myaddress#gmail.com"}]
};
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", url);
xhr.setRequestHeader("content-type", "application/json");
xhr.setRequestHeader("accept", "application/json");
xhr.setRequestHeader("authorization", creds);
xhr.setRequestHeader("cache-control", "no-cache");
xhr.send(JSON.stringify(fetchbody));
}
Is there something wrong with my credentials setup here? Note that creds is set to my secret API key string.
Figured it out after chatting with the Sparkpost devs a bit - the service only allows "strict CORS" i.e. requests from server-side, and I was sending the request from client-side code.
I'm building a small app that consumes a REST service.
The REST service expects that the URL i interact with always have the API key as an URL parameter.
So no matter if i GET, POST, UPDATE or DELETE, my URL should always contain be something like this:
https://rest.service.tld:443/list?api_key=MY-KEY
https://rest.service.tld:443/lists/1/profiles/search?api_key=MY-KEY
I tried with the sample code from RestSharp webpage, but it get the statuscode Access Denied
Here's my code:
// Create client
var client = new RestClient( "https://rest.service.tld:443" );
client.Authenticator = new SimpleAuthenticator( "api_key", "MY-KEY", "", "" );
// GET list of items
var requestLists = new RestRequest( "lists", Method.GET );
IRestResponse<List<ListResponse>> listResponse = client.Execute<List<ListResponse>>( requestLists ); // Returns the correct list
// POST search
var requestProfiles = new RestRequest( "lists/1/profiles/search", Method.POST );
requestProfiles.AddParameter( "Criteria", "{\"email\":\my#email.tld\"}" );
IRestResponse profileResponse = client.Execute( requestProfiles ); // Returns 'Access Denied' status code
As far as i can tell, the POST method doesn't contain the correct querystring, instead my api_key is added as a parameter in the POST.
Is there a way to keep my API_KEY in the Querystring like i need it to be?
By default the api_key is added as a normal parameter, you need to explicitly enforce that you want the parameter to be embedded into the URL, by setting the ParameterType as follows:
var requestProfiles = new RestRequest( "lists/1/profiles/search{api_key}", Method.POST );
requestProfiles.AddParameter( "Criteria", "{\"email\":\my#email.tld\"}" );
requestProfiles.AddParameter( "api_key", MY-KEY, ParameterType.UrlSegment);
More info here
I need to access an asp page running on 'https' protocol.
I am facing problems at authentication part itself. The response object returns "HTTP/1.1 200 OK" but i am getting redirected to Login page itself.
Following is my code:
public FileDownloadHttpWrapper(String url,String username, String password)
{
SchemeRegistry supportedSchemes = new SchemeRegistry();
supportedSchemes.register(new Scheme("https",
SSLSocketFactory.getSocketFactory(), 443));
// prepare parameters
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, "UTF-8");
HttpProtocolParams.setUseExpectContinue(params, true);
ClientConnectionManager ccm = new ThreadSafeClientConnManager(params,supportedSchemes);
mClient = new DefaultHttpClient(ccm,params);
mClient.getCredentialsProvider().setCredentials(
new AuthScope(null,AuthScope.ANY_PORT),
new UsernamePasswordCredentials(username, password)
);
}
private Object getRequest(String url)
{
HttpGet get = new HttpGet("/EvalMuniMKT/mainmenu.asp");
HttpHost target = new HttpHost(url, 443, "https");
try
{
// execute the GET
HttpResponse resp = mClient.execute(target,get);
HttpEntity entity = resp.getEntity();
System.out.println(resp.getStatusLine());
System.out.println(EntityUtils.toString(entity));
}
catch(Exception ex)
{
ex.printStackTrace();
}
finally
{
// release any connection resources used by the method
}
return null;
}
I think the asp site uses form based login (session), not http basic authentication. For that you may need to do login form post and hold cookie in context and pass the context while executing the actual request.
something like :
CookieStore cookieStore = new BasicCookieStore();
// Create local HTTP context
HttpContext localContext = new BasicHttpContext();
// Bind custom cookie store to the local context
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
hc.execute(httpget, localContext);