Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am on project right now which is a very simple parental control software, but, I want to know what is the url requested in firefox to take respond based on it ... if you may help because I don't know how to let my software know what is the url requested by firefox .. How to do that?
I have to use C++ in most of my software.. but if there are better language to do this task please advice me
In Firefox you need to use XPCOM component called nsIHTTPChannel. This script below will block abort all rqeuests to google. The channel is opened but aborted before opening connection to server.
var {classes: Cc, results: Cr, utils: Cu} = Components;
Cu.import('resource://gre/modules/Services.jsm');
var httpRequestObserver =
{
observe: function(subject, topic, data)
{
var httpChannel, requestURL;
if (topic == 'http-on-modify-request') {
httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
requestURL = httpChannel.URI.spec;
if (/google\.com/.test(requestURL)) {
httpChanel.cancel(Cr.NS_BINDING_ABORTED);
}
return;
}
}
};
Services.obs.addObserver(httpRequestObserver, 'http-on-modify-request', false);
//Services.obs.removeObserver(httpRequestObserver, "http-on-modify-request", false); //run this to remove observer
Can I suggest an alternative approach? Instead of writing an extension for Firefox and an extension for Chrome and an extension for IE... listen on the OS network interfaces for traffic and block undesirable URLS.
This is traditionally the job of a firewall. Using an existing solution will provide the most efficient means of solving your problem. I'm not familiar with the capabilities of the built in Windows firewall or 3rd party alternatives but something like this would be trivial with iptables (Linux).
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
How do i read data as text from a BLOB Url in WebView2 ? I've tried WebView2 callback from Javascript which i couldn't make it work. I appreciate whether it is a Javascript solution or not but i prefer C++.
WebView2 doesn't provide a mechanism to interact with Blobs. You can turn the Blob into text in script and then post the text back to the native side with the window.chrome.webview.postMessage method and the WebMessageReceived event.
If this doesn't work for you, you can make a feature request on the WebView2 Feedback GitHub Project.
async function example() {
function textToBlob(text) {
return new Blob([text], {type : 'text/plain'});
}
async function blobToText(blob) {
return (new Response(blob)).text();
}
const blob = textToBlob("example");
const text = await blobToText(blob);
alert(text);
}
example();
Unfortunately, Webview2 doesn't support async function results in ExecuteScript. I managed to get data by performing synchronous request with ajax.
wstring jquery(L"var jqry = document.createElement('script');"
L"jqry.src = 'https://code.jquery.com/jquery-3.3.1.min.js';"
L"document.getElementsByTagName('head')[0].appendChild(jqry);");
webview->ExecuteScript(jquery.c_str(), Callback<ICoreWebView2ExecuteScriptCompletedHandler>(
[](HRESULT errorCode, PCWSTR result) -> HRESULT {
return S_OK;
}).Get());
Sleep(500);
wstring script(L"jQuery.noConflict();"
L"function testAjax() {"
L"var result='';"
L"jQuery.ajax({"
L"url:document.getElementById('test').href,"
L"async: false,"
L"success:function(data) {"
L"result = data; "
L"}"
L"});"
L"return result;"
L"}"
L"(() => {"
L"return testAjax()"
L"})();");
webview->ExecuteScript(script.c_str(), Callback<ICoreWebView2ExecuteScriptCompletedHandler>(
[](HRESULT errorCode, LPCWSTR result) -> HRESULT {
wprintf(L"%ls\n", result);
return S_OK;
}).Get());
But synchronous calls block the web code while executing. This is not recommended, but it is ok for my case. If you are looking for another way without blocking the web code, posting the text back to the native side maybe a better idea as #David Risney suggested.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
description: Attempt an operation multiple times if it fails due to network or server errors.
I have used apollo-link-retry to retry calls on the occurrence of server errors(5xx).
But when 400 error(bad request) is occurring it retrying which is expected to retry in server error only.
Does network error means all client errors(4xx) and server errors(5xx)?
How to stop retrying on errors other than 5xx?
In the context of Apollo Client, there are two types of errors -- GraphQL errors (those returned inside the errors array in the response) and network errors. Any request that returns a status other than 200 is considered to have encountered a network error. The default RetryLink configuration is not that granular -- it only cares about whether a network error occurred, not what kind of error occurred. If you want to not retry on certain errors, provide a retryIf function to the attempts configuration as shown in the docs:
attempts: {
retryIf: (error, _operation) => {
// return true or false depending on the properties on error
}
}
})
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
is there a way to use speech recognition in an Iionic 2 Project? All I came across are possibilities for Ionic 1 like in this post Speech recognition using ionic framework . Ionic 2 already provides a native API for Text to Speech http://ionicframework.com/docs/v2/native/texttospeech/ but I would need it the other way round.
Better question to ask yourself is, is there a cordova plugin for the thing I want?
And yes there are cordova plugins available.
https://github.com/macdonst/SpeechRecognitionPlugin
https://github.com/poiuytrez/SpeechRecognizer
Just instead of using cordova plugin add ..... use ionic plugin add ...... (will immediately update platforms).
You can use this Cordova plugin for speech recognition cordova-plugin-tts
Since Ionic 2 uses TypeScript ,all you need is a way to use the plugin with TypeScript .The Github repo includes an example on how to do that
declare module TTS {
interface IOptions {
/** text to speak */
text: string;
/** a string like 'en-US', 'zh-CN', etc */
locale?: string;
/** speed rate, 0 ~ 1 */
rate?: number;
}
function speak(options: IOptions, onfulfilled: () => void, onrejected: (reason) => void): void;
function speak(text: string, onfulfilled: () => void, onrejected: (reason) => void): void;
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
So this question has been asked before, but the general answer pointed to was using an external library such as cURLpp. So I was curious as to if HTTP requests could be done using only the standard libraries as of C++14. How difficult would this be?
Say for example, I wanted to get an XML document and store it in a string to be parsed. What steps would have to be taken to achieve this?
If anyone is curious, I'm doing this as a learning experience to better understand how HTTP requests work.
It sounds like to me that you want to implement the HTTP protocol from scratch on top of the POSIX sockets API. I have done this myself, it was quite fun.
Read about the sockets API here: http://en.wikipedia.org/wiki/Berkeley_sockets
If you want to work on Windows, see here.
This link, posted in the comments, provides a pretty good starting-point example for using the API, although it weirdly includes both the client and the server as serial logic within the same program -- which may allow it to bypass some of the calls (such as waiting for incoming connections) required to implement a client or server as a standalone program.
Assuming you are implementing an HTTP server in C++, you might choose to implement the client as a web page (running on your favorite browser), as the following hack demonstrates...
<html>
<head>
</head>
<body>
This web page sends the entered text back to the server upon a button press.
The server's response is then displayed in the box below.
This is only a hack for learning purposes, and not a demonstration of best-practices.
<br>
<textarea id="INP">
Hello world!
</textarea>
<br>
<button onclick="return make_request('INP','GET','test1')">GET Request</button>
<button onclick="return make_request('INP','POST','test2')">POST Request</button>
<div id="result" style='border-style:solid;'>?</div>
<script>
function make_request( textID, request_type, webfn )
{
var url = "" + "?webfn="+webfn // assumes this page was served by the same server
if ( request_type != 'POST' ) url += "&value="+document.getElementById(textID).value;
var req = new XMLHttpRequest();
req.open( request_type, url, /*async*/false );
req.send( request_type=='POST' ? document.getElementById(textID).value : null );
if ( req.readyState == 4/*complete*/ && req.status == 200/*OK*/ )
{
result = req.responseXML.documentElement.getElementsByTagName('value')[0].firstChild.data;
document.getElementById('result').innerHTML = req.responseText;
}
else alert("HTTP request failed");
return false;
}
</script>
</body>
</html>
Compress(TInt aCompressionMethod,const TDesC8 data)
{
TInt compressionMethod = 0;
if(aCompressionMethod == 0)
compressionMethod = Z_DEFAULT_COMPRESSION;
iCompressor =CEZCompressor::NewLC(*this,Z_DEFAULT_COMPRESSION);
TRAPD(err, iCompressor->CompressL(cipher,text));
}
I am using compression using gzip method in symbian in client side and on server side server is in Java.
The problem is that on server side in Java gZip format is not matched exception is thrown.
I want to know the method I am using to compress string is correct or wrong, or whether I have to made change or server side has to change.
CEZCompressor will just give you the deflate-compressed data. It does not contain any gzip-specific header information. If your server-side java implementation needs to see that information, use the CEZGZipToFile class.
There's a nice example at Forum Nokia wiki.
Hope this helps. If not, please add details to your question. Currently it is a little bit on the vague side.