有没有办法Invoke-RestMethod
在PowerShell中调用时将返回代码存储在某处?
我的代码看起来像这样:
$url = "http://www.dictionaryapi.com/api/v1/references/collegiate/xml/Adventure?key=MyKeyGoesHere"
$XMLReturned = Invoke-RestMethod -Uri $url -Method Get;
Run Code Online (Sandbox Code Playgroud)
我没有看到我的$XMLReturned
变量中的任何地方返回代码为200.我在哪里可以找到返回代码?
我有一个图像通过JSON字符串发送给我.我想将该字符串转换为我的Android应用程序中的图像,然后显示该图像.
JSON字符串如下所示:
"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAVI..."
Run Code Online (Sandbox Code Playgroud)
注意:我用...截断了字符串
我有一个函数(我认为)将字符串转换为图像.我这样做了吗?
public Bitmap ConvertToImage(String image){
try{
InputStream stream = new ByteArrayInputStream(image.getBytes());
Bitmap bitmap = BitmapFactory.decodeStream(stream);
return bitmap;
}
catch (Exception e) {
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
然后我尝试在我的Android活动上显示它
String image = jsonObject.getString("barcode_img");
Bitmap myBitmap = this.ConvertToImage(image);
ImageView cimg = (ImageView)findViewById(R.id.imageView1);
//Now try setting dynamic image
cimg.setImageBitmap(myBitmap);
Run Code Online (Sandbox Code Playgroud)
但是,当我这样做时,什么都没有出现.我没有在logcat中得到任何错误.我究竟做错了什么?
谢谢
我有一个脚本来为给定用户在其他计算机上获取和设置用户的Windows环境变量.是否可以为该用户硬编码密码,这样我每次运行脚本时都不必输入密码?
我的脚本看起来像这样:
$s5 = New-PSSession -computername testauto2, testauto3 -Credential
Domain\testautouser
invoke-command -session $s5[0] -scriptblock {[Environment]::GetEnvironmentVariable("TestBrowser", "user")}
Run Code Online (Sandbox Code Playgroud) 我在本地计算机上有一个SQL Server实例.\SC
.我想使用PowerShell脚本从该实例中删除数据库.我需要sa
用户登录我的数据库.
这是我到目前为止的代码,但它不起作用:
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")
$srv = new-object Microsoft.SqlServer.Management.Smo.Server(".\SC")
$conContext = $srv.ConnectionContext
$conContext.LoginSecure = $FALSE
$conContext.Login = "sa"
$conContext.Password = "MyPlainTextPass"
$srv2 = new-object Microsoft.SqlServer.Management.Smo.Server($conContext)
$srv2.Databases
Run Code Online (Sandbox Code Playgroud)
最后一行应该列出我的SQL实例中的数据库......但它给了我这个错误:
尝试枚举集合时发生以下异常:"无法连接到服务器.\ SC.".在行:1 char:1 + $ srv2.Databases + ~~~~~~~~~~~~~~~ + CategoryInfo:NotSpecified:(:) [],ExtendedTypeSystemException + FullyQualifiedErrorId:ExceptionInGetEnumerator
我究竟做错了什么?
是否有一个powershell命令,我可以用来将"断开连接"的用户从服务器上踢掉?一旦我知道了单个用户的单行,我就可以编写脚本.
例如,我想踢下面对话框中看到的8个用户.
我将docker镜像上传到GCP Container注册表时遇到问题.我按照这里的说明.
正如您在下面的屏幕截图中看到的,我:
但是,我收到了这个错误:拒绝:
Please enable Google Container Registry API in Cloud Console at https://console.cloud.google.com/apis/api/containerregistry.googleapis.com/overview?project=bentestproject-184220 before performing this operation.
Run Code Online (Sandbox Code Playgroud)
当我关注该链接时,它会将我带到错误的项目:
当我选择自己的项目时,我可以看到确实启用了"Google Container Registry API":
如何上传我的泊坞窗图片?
I am using an abstract class like this:
@SpringBootTest(classes = MyAppApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
public abstract class AbstractIntegrationTest {
static {
PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer().withPassword("password")
.withUsername("postgres").withDatabaseName("MyApp");
postgreSQLContainer.start();
System.setProperty("spring.datasource.url", postgreSQLContainer.getJdbcUrl());
System.setProperty("spring.datasource.password", postgreSQLContainer.getPassword());
System.setProperty("spring.datasource.username", postgreSQLContainer.getUsername());
}
Run Code Online (Sandbox Code Playgroud)
Then I have many tests that leverage that use that class like this:
public class moreTests extends AbstractIntegrationTest {
TestRestTemplate restTemplate = new TestRestTemplate("my-user", "password");
HttpHeaders headers = new HttpHeaders();
@Test
public void SimpleHealthCheck() {
HttpEntity<String> entity = new HttpEntity<String>(null, headers);
ResponseEntity<String> response = …
Run Code Online (Sandbox Code Playgroud) 我想为Android应用程序编写Robotium/Junit测试.在某些步骤中,我希望我的测试等到旋转加载符号从屏幕上消失.
我怎样才能做到这一点?
我有一个简单的Android小部件,我想用互联网上的图像更新.我可以在小部件上显示静态图像没问题.我被告知你需要使用异步任务,我对这些没有多少经验.
这是我的小部件:
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
super.onUpdate(context, appWidgetManager, appWidgetIds);
for (int i = 0; i < appWidgetIds.length; i++){
int appWidgetId = appWidgetIds[i];
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.activity_main);
//Setup a static image, this works fine.
views.setImageViewResource(R.id.imageView1, R.drawable.wordpress_icon);
new DownloadBitmap().execute("MyTestString");
appWidgetManager.updateAppWidget(appWidgetId, views);
}
Run Code Online (Sandbox Code Playgroud)
然后我有一个异步任务类来进行下载.它看起来像这样:
public class DownloadBitmap extends AsyncTask<String, Void, Bitmap> {
/** The url from where to download the image. */
private String url = "http://0.tqn.com/d/webclipart/1/0/5/l/4/floral-icon-5.jpg";
@Override
protected Bitmap doInBackground(String... params) {
try { …
Run Code Online (Sandbox Code Playgroud) 我正在使用Microsoft Server 2008计算机.出于某种原因,命令"psexec"在这台1台机器上的PowerShell中无效.
当我尝试运行它时,我得到了这个:
PS C:\> psexec
The term 'psexec' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At line:1 char:7
+ psexec <<<<
+ CategoryInfo : ObjectNotFound: (psexec:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\>
Run Code Online (Sandbox Code Playgroud)
它正在运行powershell 2.0.我发现这一点:
PS C:\> $Host.Version
Major Minor Build Revision
----- ----- ----- --------
2 0 …
Run Code Online (Sandbox Code Playgroud) 当我打开一个Windows命令提示符并输入"set"然后输入时,我得到一个系统变量列表.
如何使用visual studio在C#中设置/获取它们?
我试过了:
System.Environment.SetEnvironmentVariable("TestVariableName", "test123");
Run Code Online (Sandbox Code Playgroud)
但是,当我在命令行中输入"set"时,我没有看到名为"TestVariableName"的新变量,其值为"test123".
我究竟做错了什么?
谢谢
我正在编写一个Powershell脚本,它使用本地SQL Server数据库执行多项操作.
我正在做的一件事是一个接一个地运行几个SQL作业.我像这样运行它们:
sqlcmd -S .\ -Q "EXECUTE msdb.dbo.sp_start_job @job_name = 'Rebuild Content Asset Relationship Data'"
Run Code Online (Sandbox Code Playgroud)
有没有办法让Powershell延迟运行下一个工作,直到完成第一个工作?
谢谢
powershell ×6
android ×3
java ×2
sql-server ×2
api ×1
c# ×1
command-line ×1
docker ×1
gcp ×1
image ×1
junit ×1
passwords ×1
postgresql ×1
psexec ×1
robotium ×1
spring-boot ×1
system ×1
variables ×1
widget ×1